﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Security.Cryptography;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
using System.Net;
using System.IO;
using System.IO.Compression;
using System.Text.RegularExpressions;
using System.Runtime.Serialization.Formatters.Binary;
using System.Xml;
using System.Threading;


namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        XmlDocument xmla = null;
        XmlDocument areaxml = null;
        bool bkey1 = true;
        int iSubBossID = 0;
        int iNowBossID = 0;
        Thread workerThread;
        int[] arthalist = new int[9];
        int iArthaNum = -1;
        int iArthaCount = 0;
        int iSellPrice = 600;
        int iJobID = -1;
        string cardMr = "167045362";
        string szuser = "";
        string cardFull = "180925428,156207783,161863479,174988758,167045362,180925502,177996030,162667286,180925396,181174444,173561730,174987873";
        string card3 = "174988758,167045362,173561730,empty,empty,empty,empty,empty,empty,empty,empty,empty";
        string lr3 = "167045362";
        string card6 = "174988758,167045362,173561730,empty,empty,empty,empty,empty,empty,empty,empty,empty";
        string lr6 = "167045362";
        string cardMaid = "158796096,empty,empty,empty,empty,empty,empty,empty,empty,empty,empty,empty";
        string lrMaid = "158796096";
        string cardwolf = "158796096,empty,empty,empty,empty,empty,empty,empty,empty,empty,empty,empty";
        string lrwolf = "158796096";
        string key0 = "uH9JF2cHf6OppaC10000000000000000";
        string key1 = "uH9JF2cHf6OppaC1000hentaisama997";
        string key11 = "uH9JF2cHf6OppaC1000000000ayaseuz";
        string key12 = "uH9JF2cHf6OppaC1ayaseuz000000000";
        string key2 = "A1dPUcrvur2CRQylayaseuz000000000";
        string key3 = "A1dPUcrvur2CRQyl0000000000000000";
        string key4 = "A1dPUcrvur2CRQyl000000000ayaseuz";
        string szFloor = "1";
        string szBattleLog = "";
        string szActionLog = "";
        int iAreaID = 0;
        string AreaName = "";
        int iGuildID = 0;
        int iSerialID = 0;
        string szSkill = "dummy";
        int master_boss_id;
	    int serial_id;
	    string bname;
	    int lv;
	    int hp;
        int hp_max;
        int AArthurCount = 0;
        int AAPcount = 0;
        int ECount = 0;
        int EBCCount = 0;
        int BC = 0;
        int MaxBc = 0;
        int AP = 0;
        int MaxAP = 0;
        bool bBonus = false;
        bool bThread = false;
        int iCardNum = -1;
        bool bThreadSell = false;
        bool bK = true;
        bool bWinner = false;
        int iContribution = 0;
        int iContribution2 = 0;
        private static readonly string DefaultUserAgent = "Million/227 (c1lgt; c1lgt; 4.1.2) samsung/c1lgt/c1lgt:4.1.2/JZO54K/E210LKLJME2:user/release-keys GooglePlay";
        private void thraedSell()
        {
            while(-1 != getRewardsAll());
            bThreadSell = false;
        }
        private void threada()
        {
            startTime = DateTime.Now;
            startTime2 = DateTime.Now;
            iContTatal = 0;
            iContTatal2 = 0;
            iContTatal3 = 0;
            iContTatal4 = 0;
            iNormCount2 = 0;
            iNormCount = 0;
            iNoBcCount = 0;
            iNoBcCount2 = 0;

            AArthurCount = 0;
            AAPcount = 0;
            ECount = 0;
            EBCCount = 0;
            while (bThread)
            {
                int i = DateTime.Now.Hour;
                if (i >= 1 && i < 4)
                {
                    Thread.Sleep(60000);
                    bK = false;
                    startTime = DateTime.Now;
                    startTime2 = DateTime.Now;
                    iContTatal = 0;
                    iContTatal2 = 0;
                    iContTatal3 = 0;
                    iContTatal4 = 0;
                    iNormCount2 = 0;
                    iNoBcCount2 = 0;
                    iNormCount = 0;
                    iNoBcCount = 0;

                    AArthurCount = 0;
                    AAPcount = 0;
                    ECount = 0;
                    EBCCount = 0;
                    continue;
                }
                AtackNow();
                Thread.Sleep(1000);
            }
        }
        private void threade()
        {
            while (bThread)
            {
                if (AP < 30)
                {
                    GetAP();
                }
                if (AP > 30)
                {
                    explore();
                }
                Thread.Sleep(1000);
            }
        }
        private void selectKey(string userName)
        {
            key12 = "uH9JF2cHf6OppaC1" + userName;
            for (int i = key12.Length; i < 32;i++ )
            {
                key12 += "0";
            }
        }
        private int changejob(int i)
        {
            IDictionary<string, string> parameters = new Dictionary<string, string>()
            {
                {"",""}
            };
            parameters.Clear();
            parameters.Add("jid", Encrypt(i.ToString(), key12));
            string ulr = "http://" + textBox18.Text +"/connect/app/job/change_job?cyt=1";
            CookieCollection cookies = new CookieCollection();
            Cookie c = new Cookie("S", textBox3.Text);
            c.Domain = "web.million-arthurs.com";
            cookies.Add(c);
            XmlDocument xml = null;

            while (true)
            {
                try
                {
                    xml = CreatePostHttpResponse(ulr, parameters, (int?)50000, string.Empty, Encoding.Default, cookies);
                    break;
                }
                catch (System.Exception ex)
                {
                    return -2;
                }
            }
            if (xml.InnerText != "")
            {
                if (int.Parse(xml.SelectSingleNode("response").SelectSingleNode("header").SelectSingleNode("error").SelectSingleNode("code").InnerText) == 0)
                {
                    return -1;
                }
                if (!bThread)
                {
                    TreeNode treenode = new TreeNode();
                    TreeNode subtreenode = new TreeNode();
                    TreeNode subtreenode1 = new TreeNode();
                    //treeView1.SelectedNode.Remove();
                    treeView1.Nodes.Clear();
                    treenode = treeView1.Nodes.Add(xml.DocumentElement.Name);
                    foreach (XmlNode node in xml.DocumentElement)
                    {
                        subNode(treenode, node);

                    }
                }
            }
            return 0;
        }
        private int sellcard(string str)
        {
            IDictionary<string, string> parameters = new Dictionary<string, string>()
            {
                {"",""}
            };
            parameters.Clear();
            parameters.Add("serial_id", Encrypt(str, key12));
            string ulr = "http://" + textBox18.Text +"/connect/app/trunk/sell?cyt=1";
            CookieCollection cookies = new CookieCollection();
            Cookie c = new Cookie("S", textBox3.Text);
            c.Domain = "web.million-arthurs.com";
            cookies.Add(c);
            XmlDocument xml = null;

            while (true)
            {
                try
                {
                    xml = CreatePostHttpResponse(ulr, parameters, (int?)50000, string.Empty, Encoding.Default, cookies);
                    break;
                }
                catch (System.Exception ex)
                {
                    continue;
                }
            }
            if (xml.InnerText != "")
            {
                if (int.Parse(xml.SelectSingleNode("response").SelectSingleNode("header").SelectSingleNode("error").SelectSingleNode("code").InnerText) == 8000)
                {
                    return -1;
                }
                XmlNode node0 = xml.SelectSingleNode("response").SelectSingleNode("header").SelectSingleNode("your_data");
                XmlNode nodeBC = node0.SelectSingleNode("bc");
                BC = int.Parse(nodeBC.SelectSingleNode("current").InnerText);
                MaxBc = int.Parse(nodeBC.SelectSingleNode("max").InnerText);
                XmlNode nodeAP = node0.SelectSingleNode("ap");
                AP = int.Parse(nodeAP.SelectSingleNode("current").InnerText);
                MaxAP = int.Parse(nodeAP.SelectSingleNode("max").InnerText); 
                XmlNodeList nodeCardlist = node0.SelectSingleNode("owner_card_list").SelectNodes("user_card");
                if (nodeCardlist.Count >= 190)
                {
                    return -1;
                }
                if (!bThread)
                {
                    TreeNode treenode = new TreeNode();
                    TreeNode subtreenode = new TreeNode();
                    TreeNode subtreenode1 = new TreeNode();
                    //treeView1.SelectedNode.Remove();
                    treeView1.Nodes.Clear();
                    treenode = treeView1.Nodes.Add(xml.DocumentElement.Name);
                    foreach (XmlNode node in xml.DocumentElement)
                    {
                        subNode(treenode, node);

                    }
                }
            }
            return 0;
        }
        private int getRewards(string strr)
        {
            IDictionary<string, string> parameters = new Dictionary<string, string>()
            {
                {"",""}
            };
            parameters.Clear();
            parameters.Add("notice_id", Encrypt(strr, key12));
            string ulr = "http://" + textBox18.Text +"/connect/app/menu/get_rewards?cyt=1";
            CookieCollection cookies = new CookieCollection();
            Cookie c = new Cookie("S", szcookie);
            c.Domain = "web.million-arthurs.com";
            cookies.Add(c);
            XmlDocument xml = null;

            while (true)
            {
                try
                {
                    xml = CreatePostHttpResponse(ulr, parameters, (int?)50000, string.Empty, Encoding.Default, cookies);
                    break;
                }
                catch (System.Exception ex)
                {
                    continue;
                }
            }
            if (xml.InnerText != "")
            {
                //if (int.Parse(xml.SelectSingleNode("response").SelectSingleNode("header").SelectSingleNode("error").SelectSingleNode("code").InnerText) != 0)
                //{
                //    return;
                //}
//                 XmlNode node0 = xml.SelectSingleNode("response").SelectSingleNode("header").SelectSingleNode("your_data");
//                 XmlNode nodeBC = node0.SelectSingleNode("bc");
//                 BC = int.Parse(nodeBC.SelectSingleNode("current").InnerText);
//                 MaxBc = int.Parse(nodeBC.SelectSingleNode("max").InnerText);
//                 XmlNode nodeAP = node0.SelectSingleNode("ap");
//                 AP = int.Parse(nodeAP.SelectSingleNode("current").InnerText);
//                 MaxAP = int.Parse(nodeAP.SelectSingleNode("max").InnerText);
//                 string strsell = "";
//                 XmlNodeList nodeCardlist = null;
//                 int isellnum = 0;
// 
//                 nodeCardlist = node0.SelectSingleNode("owner_card_list").SelectNodes("user_card");
// 
//                 foreach (XmlNode nodes in nodeCardlist)
//                 {
//                     int icardlv = int.Parse(nodes.SelectSingleNode("lv").InnerText);
//                     int icardlvmax = int.Parse(nodes.SelectSingleNode("lv_max").InnerText);
//                     int icardsale_price = int.Parse(nodes.SelectSingleNode("sale_price").InnerText);
//                     int icardhp = int.Parse(nodes.SelectSingleNode("hp").InnerText);
//                     int icardpower = int.Parse(nodes.SelectSingleNode("power").InnerText);
//                     if (icardlv == 1)
//                     {
//                         if (icardhp > 1 || icardpower > 1)
//                         {
//                             if (icardsale_price < iSellPrice)
//                             {
//                                 if (isellnum == 0)
//                                 {
//                                     strsell += nodes.SelectSingleNode("serial_id").InnerText;
//                                 } 
//                                 else
//                                 {
//                                     strsell += "," + nodes.SelectSingleNode("serial_id").InnerText;
//                                 }
//                                 isellnum++;
//                             }
//                         }
//                     }
//                     else if (icardlvmax < 40)
//                     {
//                         if (isellnum == 0)
//                         {
//                             strsell += nodes.SelectSingleNode("serial_id").InnerText;
//                         }
//                         else
//                         {
//                             strsell += "," + nodes.SelectSingleNode("serial_id").InnerText;
//                         }
//                         isellnum++;
//                     }
//                     if (isellnum == 30)
//                     {
//                         if(-1==sellcard(strsell)) return -1;
//                         isellnum = 0;
//                         strsell = "";
//                     }
//                 }
//                 if (strsell != "")
//                 {
//                     if (-1 == sellcard(strsell)) return -1;
//                 }
//                 if (!bThread)
//                 {
//                     TreeNode treenode = new TreeNode();
//                     TreeNode subtreenode = new TreeNode();
//                     TreeNode subtreenode1 = new TreeNode();
//                     //treeView1.SelectedNode.Remove();
//                     treeView1.Nodes.Clear();
//                     treenode = treeView1.Nodes.Add(xml.DocumentElement.Name);
//                     foreach (XmlNode node in xml.DocumentElement)
//                     {
//                         subNode(treenode, node);
// 
//                     }
//                 }
            }
            return 0;
        }
        private int getRewardsAll()
        {
            IDictionary<string, string> parameters = new Dictionary<string, string>()
            {
                {"",""}
            };
            parameters.Clear();
            string ulr = "http://" + textBox18.Text +"/connect/app/menu/rewardbox?cyt=1";
            CookieCollection cookies = new CookieCollection();
            Cookie c = new Cookie("S", szcookie);
            c.Domain = "web.million-arthurs.com";
            cookies.Add(c);
            XmlDocument xml = null;

            while (true)
            {
                try
                {
                    xml = CreatePostHttpResponse(ulr, parameters, (int?)50000, string.Empty, Encoding.Default, cookies);
                    break;
                }
                catch (System.Exception ex)
                {
                    continue;
                }
            }
            if (xml.InnerText != "")
            {
                if (int.Parse(xml.SelectSingleNode("response").SelectSingleNode("header").SelectSingleNode("error").SelectSingleNode("code").InnerText) != 0)
                {
                    return -1;
                }
                XmlNode node0 = null;

                XmlNodeList nodeboxs = null;
                try
                {
                    node0 = xml.SelectSingleNode("response").SelectSingleNode("body").SelectSingleNode("rewardbox_list");

                    nodeboxs = node0.SelectNodes("rewardbox");
                }
                catch (System.Exception ex)
                {
                    return -1;
                }
                if (nodeboxs == null)
                {
                    return -1;
                }
                else if (nodeboxs.Count == 0)
                {
                    return -1;
                }
                string strbox = "";
                int i = 0;
                foreach (XmlNode nodes in nodeboxs)
                {
                    if (i == 0)
                    {
                        strbox += nodes.SelectSingleNode("id").InnerText;
                    } 
                    else
                    {
                        strbox += "," + nodes.SelectSingleNode("id").InnerText;
                    }
                    i++;
                }
                return getRewards(strbox);
                //if (!bThread)
                //{
                //    TreeNode treenode = new TreeNode();
                //    TreeNode subtreenode = new TreeNode();
                //    TreeNode subtreenode1 = new TreeNode();
                //    //treeView1.SelectedNode.Remove();
                //    treeView1.Nodes.Clear();
                //    treenode = treeView1.Nodes.Add(xml.DocumentElement.Name);
                //    foreach (XmlNode node in xml.DocumentElement)
                //    {
                //        subNode(treenode, node);

                //    }
                //}
            }
            return -1;
        }
        private void getapbc()
        {
            if (iAreaID == 0)
            {
                GetAreaIfo();
            }
            IDictionary<string, string> parameters = new Dictionary<string, string>()
            {
                {"",""}
            };
            parameters.Clear();
            string s1 = "1";
            parameters.Add("area_id", Encrypt(iAreaID.ToString(), key12));
            parameters.Add("check", Encrypt(s1.ToString(), key12));
            parameters.Add("floor_id", Encrypt(s1.ToString(), key12));
            string ulr = "http://" + textBox18.Text +"/connect/app/exploration/get_floor?cyt=1";
            CookieCollection cookies = new CookieCollection();
            Cookie c = new Cookie("S", textBox3.Text);
            c.Domain = "web.million-arthurs.com";
            cookies.Add(c);
            XmlDocument xml = null;

            while (true)
            {
                try
                {
                    xml = CreatePostHttpResponse(ulr, parameters, (int?)50000, string.Empty, Encoding.Default, cookies);
                    break;
                }
                catch (System.Exception ex)
                {
                    continue;
                }
            }
            if (xml.InnerText != "")
            {
                if (int.Parse(xml.SelectSingleNode("response").SelectSingleNode("header").SelectSingleNode("error").SelectSingleNode("code").InnerText) != 0)
                {
                    return;
                }
                XmlNode node0 = xml.SelectSingleNode("response").SelectSingleNode("header").SelectSingleNode("your_data");
                XmlNode nodeBC = node0.SelectSingleNode("bc");
                BC = int.Parse(nodeBC.SelectSingleNode("current").InnerText);
                MaxBc = int.Parse(nodeBC.SelectSingleNode("max").InnerText);
                XmlNode nodeAP = node0.SelectSingleNode("ap");
                AP = int.Parse(nodeAP.SelectSingleNode("current").InnerText);
                MaxAP = int.Parse(nodeAP.SelectSingleNode("max").InnerText);
                if (!bThread)
                {
                    TreeNode treenode = new TreeNode();
                    TreeNode subtreenode = new TreeNode();
                    TreeNode subtreenode1 = new TreeNode();
                    //treeView1.SelectedNode.Remove();
                    treeView1.Nodes.Clear();
                    treenode = treeView1.Nodes.Add(xml.DocumentElement.Name);
                    foreach (XmlNode node in xml.DocumentElement)
                    {
                        subNode(treenode, node);

                    }
                }
            }
        }
        private int explore()
        {
            int iRe = -1;
            if (iAreaID == 0)
            {
                GetAreaIfo();
            }
            IDictionary<string, string> parameters = new Dictionary<string, string>()
            {
                {"",""}
            };
            parameters.Clear();
           string s1 = "1";
            parameters.Add("area_id", Encrypt(iAreaID.ToString(), key12));
            parameters.Add("auto_build", Encrypt(s1.ToString(), key12));
            parameters.Add("floor_id", Encrypt(szFloor, key12));
            string ulr = "http://" + textBox18.Text +"/connect/app/exploration/guild_explore?cyt=1";
            CookieCollection cookies = new CookieCollection();
            Cookie c = new Cookie("S", textBox3.Text);
            c.Domain = "web.million-arthurs.com";
            cookies.Add(c);
            XmlDocument xml = null;

            while (true)
            {
                try
                {
                    xml = CreatePostHttpResponse(ulr, parameters, (int?)50000, string.Empty, Encoding.Default, cookies);
                    break;
                }
                catch (System.Exception ex)
                {
                    continue;
                }
            }
            if (xml.InnerText != "")
            {
                string szLogTemp = "移动：";
                if (int.Parse(xml.SelectSingleNode("response").SelectSingleNode("header").SelectSingleNode("error").SelectSingleNode("code").InnerText) != 0)
                {
                    GetAreaIfo();
                    szLogTemp += xml.SelectSingleNode("response").SelectSingleNode("header").SelectSingleNode("error").SelectSingleNode("message").InnerText + "\r\n";
                    szActionLog += szLogTemp;
                    return iRe;
                }
                XmlNode node0 = xml.SelectSingleNode("response").SelectSingleNode("header").SelectSingleNode("your_data");
                XmlNode nodeBC = node0.SelectSingleNode("bc");
                int oldAp = AP;
                int oldBC = BC;
                BC = int.Parse(nodeBC.SelectSingleNode("current").InnerText);
                MaxBc = int.Parse(nodeBC.SelectSingleNode("max").InnerText);
                XmlNode nodeAP = node0.SelectSingleNode("ap");
                AP = int.Parse(nodeAP.SelectSingleNode("current").InnerText);
                MaxAP = int.Parse(nodeAP.SelectSingleNode("max").InnerText);
                iRe = int.Parse(xml.SelectSingleNode("response").SelectSingleNode("body").SelectSingleNode("explore").SelectSingleNode("event_type").InnerText);
                if (iRe == 13) EBCCount++;
                ECount++;
                if (iRe == 1) getGuidIFO();
                szLogTemp += "事件ID:" + iRe.ToString();
                szLogTemp += "  AP:" + oldAp.ToString() + "-" + AP.ToString() + " BC:" + oldBC.ToString() + "-" + BC.ToString() + "\r\n";
                szActionLog += szLogTemp;
            }
            return iRe;
        }
        private void GetAreaIfo()
        {
            string ulr = "http://" + textBox18.Text +"/connect/app/exploration/area?cyt=1";
            CookieCollection cookies = new CookieCollection();
            Cookie c = new Cookie("S", textBox3.Text);
            c.Domain = "web.million-arthurs.com";
            cookies.Add(c);
            XmlDocument xml = null;

            while (true)
            {
                try
                {
                    xml = CreatePostHttpResponse(ulr, null, (int?)50000, string.Empty, Encoding.Default, cookies);
                    break;
                }
                catch (System.Exception ex)
                {
                    continue;
                }
            }
            areaxml = xml;
            if (xml.InnerText != "")
            {
                XmlNode node1 = xml.SelectSingleNode("response").SelectSingleNode("body").SelectSingleNode("exploration_area").SelectSingleNode("area_info_list");
                foreach (XmlNode nodes in node1.ChildNodes)
                {
                    XmlNode node2 = nodes.SelectSingleNode("area_type");
                    if (node2.InnerText == "0")
                    {
                        break;
                    }
                    int id = int.Parse(nodes.SelectSingleNode("id").InnerText);
                    if (id != 0 && id != 50002 && id != 50004 && id != 50005)
                    {
                        AreaName = nodes.SelectSingleNode("name").InnerText;
                        iAreaID = id;
                    }
                }
            }
            
        }
        private void ChangeCard(int iCard)
        {
            if (iCardNum != iCard)
            {
                IDictionary<string, string> parameters = new Dictionary<string, string>()
                {
                    {"",""}
                };
                parameters.Clear();
                string szcardName = "";
                switch (iCard)
                {
                    case 0:
                        parameters.Add("C", Encrypt(cardFull, key12));
                        parameters.Add("lr", Encrypt(cardMr, key12));
                        szcardName = "全卡";
                        break;
                    case 1:
                        parameters.Add("C", Encrypt(card3, key12));
                        parameters.Add("lr", Encrypt(lr3, key12));
                        szcardName = "3卡";
                        break;
                    case 2:
                        parameters.Add("C", Encrypt(cardMaid, key12));
                        parameters.Add("lr", Encrypt(lrMaid, key12));
                        szcardName = "点名";
                        break;
                    case 3:
                        parameters.Add("C", Encrypt(cardwolf, key12));
                        parameters.Add("lr", Encrypt(lrwolf, key12));
                        szcardName = "狼娘";
                        break;
                    case 4:
                        parameters.Add("C", Encrypt(card6, key12));
                        parameters.Add("lr", Encrypt(lr6, key12));
                        szcardName = "6卡";
                        break;
                }
                string ulr = "http://" + textBox18.Text +"/connect/app/cardselect/savedeckcard?cyt=1";
                CookieCollection cookies = new CookieCollection();
                Cookie c = new Cookie("S", textBox3.Text);
                c.Domain = "web.million-arthurs.com";
                cookies.Add(c);
                XmlDocument xml = null;

                while (true)
                {
                    try
                    {
                        xml = CreatePostHttpResponse(ulr, parameters, (int?)50000, string.Empty, Encoding.Default, cookies);
                        iCardNum = iCard;
                        break;
                    }
                    catch (System.Exception ex)
                    {
                        continue;
                    }
                }
                szActionLog += "换卡：" + szcardName + "\r\n";
            }
        }
        int iWaitCount = 0;
        int iNoBcCount = 0;
        int iNormCount = 0;
        int iNoBcCount2 = 0;
        int iNormCount2 = 0;
        private void AtackNow()
        {
            //if (iGuildID == 0) iGuildID = getGuildID();
            int iRE = getGuidIFO();

            if (MaxAP == 0)
            {
                getapbc();
            }
            while (iRE == 2  || hp == 0)
            {
                int i = DateTime.Now.Hour;
                if (i >= 1 && i < 4)
                {
                    return;
                }
                if (!bThread)
                {
                    return;
                }
                if (MaxAP == 0)
                {
                    getapbc();
                }
                else if(AP > 1)
                {
                    explore();
                }
                else if (iWaitCount > 20)
                {
                    getapbc();
                    iWaitCount = 0;
                }
                else
                {
                    GetAP();
                    iWaitCount++;
                }
                iRE = getGuidIFO();
                
            }
            if (iRE == 1)
            {
                iRE = getGuidIFO();
            }
            if (bBonus)
            {
                ChangeCard(0);
                if (AtacktONE(iGuildID, serial_id) == -1) getapbc();
                iNoBcCount++;
                iNoBcCount2++;
                if (bWinner) explore();
                else if (AP < 30)
                {
                    GetAP();
                }
                else if (BC < MaxBc - 90)
                {
                    explore();
                }
            }
            else
            {
                int ibc = lv < 90 ? 90 : 180;
                if (BC > ibc && iRE != 3)
                {
                    if (lv < 90) ChangeCard(1); else ChangeCard(4);
                    if (AtacktONE(iGuildID, serial_id) == -1) getapbc();
                    iNormCount++;
                    iNormCount2++;
                    if (bWinner) explore();
                    //if(bK)AtacktONE(89625, 5087312);
                }
                else if (iRE == 3)
                {
                    ChangeCard(3);
                    if (AtacktONE(iGuildID, serial_id) == -1) getapbc();
                    if (bWinner) explore();
                }
                else if (iWaitCount > 20)
                {
                    getapbc();

                    if (AP < 30)
                    {
                        GetAP();
                    }
                    else if (BC < MaxBc - 90)
                    {
                        explore();
                    }
                    iWaitCount = 0;
                }
                else
                {
                    if (AP < 30)
                    {
                        GetAP();
                    }
                    else if (BC < MaxBc - 90)
                    {
                        explore();
                    }
                    iWaitCount++;
                }
            }
        }
        private int GetAP()
        {
            while (iArthaCount == 0 || iArthaNum == -1 || iArthaNum == iArthaCount - 1)
            {
                SearchArtha();
            }
            ChangeCard(2);
            int ire =AtactArtha(arthalist[iArthaNum]);
            iArthaNum++;
            return ire;
        }
        private int SearchArtha()
        {
            int iRe = -1;
            IDictionary<string, string> parameters = new Dictionary<string, string>()
            {
                {"",""}
            };
            string s0 = "0";
            parameters.Clear();
            parameters.Add("name", Encrypt("名", key12));
            string ulr = "http://" + textBox18.Text +"/connect/app/menu/player_search?cyt=1";
            CookieCollection cookies = new CookieCollection();
            Cookie c = new Cookie("S", textBox3.Text);
            c.Domain = "web.million-arthurs.com";
            cookies.Add(c);
            XmlDocument xml = null;

            while (true)
            {
                try
                {
                    xml = CreatePostHttpResponse(ulr, parameters, (int?)50000, string.Empty, Encoding.Default, cookies);
                    break;
                }
                catch (System.Exception ex)
                {
                    continue;
                }
            }

            if (xml.InnerText != "")
            {
                if (int.Parse(xml.SelectSingleNode("response").SelectSingleNode("header").SelectSingleNode("error").SelectSingleNode("code").InnerText) != 0)
                {
                    return iRe;
                }
                XmlNode node0 = xml.SelectSingleNode("response").SelectSingleNode("body").SelectSingleNode("player_search").SelectSingleNode("user_list");
                iArthaCount = 0;
                for (int i = 0; i < 9;i++ )
                {
                    if (int.Parse(node0.ChildNodes[i + 1].SelectSingleNode("town_level").InnerText) < 5)
                    {
                        arthalist[iArthaCount] = int.Parse(node0.ChildNodes[i + 1].SelectSingleNode("id").InnerText);
                        iArthaCount++;
                    }
                }
                iArthaNum = 0;
                
                iRe = 0;
            }
            return iRe;
        }

        DateTime dtold = DateTime.Now;
        private int AtactArtha(int iArtha)
        {
            int iRe = -1;
            DateTime dt = DateTime.Now;
            TimeSpan ts = dt - dtold;
            if (ts.TotalSeconds < 16)
            {
                return iRe;
            }
            IDictionary<string, string> parameters = new Dictionary<string, string>()
            {
                {"",""}
            };
            string s0 = "0";
            parameters.Clear();
            parameters.Add("lake_id", Encrypt(s0, key12));
            parameters.Add("parts_id", Encrypt(s0, key12));
            parameters.Add("user_id", Encrypt(iArtha.ToString(), key12));
            string ulr = "http://" + textBox18.Text +"/connect/app/battle/battle?cyt=1";
            CookieCollection cookies = new CookieCollection();
            Cookie c = new Cookie("S", textBox3.Text);
            c.Domain = "web.million-arthurs.com";
            cookies.Add(c);
            XmlDocument xml = null;

            while (true)
            {
                try
                {
                    xml = CreatePostHttpResponse(ulr, parameters, (int?)50000, string.Empty, Encoding.Default, cookies);
                    break;
                }
                catch (System.Exception ex)
                {
                    continue;
                }
            }

            if (xml.InnerText != "")
            {
                string szlogtemp = "点名：";
                if (int.Parse(xml.SelectSingleNode("response").SelectSingleNode("header").SelectSingleNode("error").SelectSingleNode("code").InnerText) != 0)
                {
                    System.Diagnostics.Trace.WriteLine("error code :" + xml.SelectSingleNode("response").SelectSingleNode("header").SelectSingleNode("error").SelectSingleNode("code").InnerText
                        + " message: " + xml.SelectSingleNode("response").SelectSingleNode("header").SelectSingleNode("error").SelectSingleNode("message").InnerText + "\r\n");
                    szlogtemp += xml.SelectSingleNode("response").SelectSingleNode("header").SelectSingleNode("error").SelectSingleNode("message").InnerText + "\r\n";
                    szActionLog += szlogtemp;
                    return int.Parse(xml.SelectSingleNode("response").SelectSingleNode("header").SelectSingleNode("error").SelectSingleNode("code").InnerText);
                }
                XmlNode node0 = xml.SelectSingleNode("response").SelectSingleNode("header").SelectSingleNode("your_data");
                XmlNode nodeBC = node0.SelectSingleNode("bc");
                int oldAp = AP;
                int oldBC = BC;
                BC = int.Parse(nodeBC.SelectSingleNode("current").InnerText);
                MaxBc = int.Parse(nodeBC.SelectSingleNode("max").InnerText);
                XmlNode nodeAP = node0.SelectSingleNode("ap");
                AP = int.Parse(nodeAP.SelectSingleNode("current").InnerText);
                MaxAP = int.Parse(nodeAP.SelectSingleNode("max").InnerText);
                if (AP - oldAp >= 10)
                    AAPcount++; 
                AArthurCount++;
                szlogtemp += "AP:" + oldAp.ToString() + "-" + AP.ToString() + " BC:" + oldBC.ToString() + "-" + BC.ToString() + "\r\n";
                szActionLog += szlogtemp;
                iRe = 0;

                dtold = dt;
            }
            return iRe;
        }
        private int AtacktONE(int iG,int iS,string SK ="dummy")
        {
            int iRe = -1;
            IDictionary<string, string> parameters = new Dictionary<string, string>()
            {
                {"",""}
            };
            parameters.Clear();
            parameters.Add("guild_id", Encrypt(iG.ToString(),key12));
            parameters.Add("serial_id", Encrypt(iS.ToString(), key12));
            parameters.Add("spp_skill_serial", Encrypt(SK, key12));
            string ulr = "http://" + textBox18.Text +"/connect/app/fairy/guild_fairy_battle?cyt=1";
            CookieCollection cookies = new CookieCollection();
            Cookie c = new Cookie("S", textBox3.Text);
            c.Domain = "web.million-arthurs.com";
            cookies.Add(c);
            XmlDocument xml = null;

            while (true)
            {
                try
                {
                    xml = CreatePostHttpResponse(ulr, parameters, (int?)50000, string.Empty, Encoding.Default, cookies);
                    break;
                }
                catch (System.Exception ex)
                {
                    return iRe;
                }
            }
            xmla = xml;
            if (xml.InnerText != "")
            {
                string szlogtemp = "战斗：";
                if (int.Parse(xml.SelectSingleNode("response").SelectSingleNode("header").SelectSingleNode("error").SelectSingleNode("code").InnerText) != 0)
                {
                    szlogtemp += xml.SelectSingleNode("response").SelectSingleNode("header").SelectSingleNode("error").SelectSingleNode("message").InnerText + "\r\n";
                    szActionLog += szlogtemp;
                    return iRe;
                }
                XmlNode node0 = xml.SelectSingleNode("response").SelectSingleNode("header").SelectSingleNode("your_data");
                if (node0 == null)
                {
                    node0 = xml.SelectSingleNode("response").SelectSingleNode("body");
                    string szName = node0.ChildNodes[0].Name;
                    if (szName == "guild_top")
                    {
                        szlogtemp += "已死\r\n";
                        XmlNode node1 = node0.SelectSingleNode("guild_top").SelectSingleNode("guild_top_update");
                        XmlNode nodd3 = node1.SelectSingleNode("guild_reward_list");
                        if (nodd3 != null)
                        {
                            bBonus = true;
                        }
                        else
                        {
                            bBonus = false;
                        }
                        XmlNode node2 = node1.SelectSingleNode("fairy");
                        //master_boss_id = int.Parse(node2.SelectSingleNode("master_boss_id").InnerText);
                        XmlNodeList nodelogs = node1.SelectNodes("guild_log");
                        szBattleLog = string.Empty;
                        foreach (XmlNode nodes in nodelogs)
                        {
                            szBattleLog += nodes.SelectSingleNode("log_time").InnerText + " - ";
                            szBattleLog += nodes.SelectSingleNode("user_name").InnerText + ":   ";
                            szBattleLog += nodes.SelectSingleNode("message").InnerText + "\r\n\r\n";
                        }
                        serial_id = int.Parse(node2.SelectSingleNode("serial_id").InnerText);
                        lv = int.Parse(node2.SelectSingleNode("lv").InnerText);
                        hp = int.Parse(node2.SelectSingleNode("hp").InnerText);
                        hp_max = int.Parse(node2.SelectSingleNode("hp_max").InnerText);
                        bname = node2.SelectSingleNode("name").InnerText;
                        iGuildID = int.Parse(node2.SelectSingleNode("discoverer_id").InnerText);
                        int timel = int.Parse(node2.SelectSingleNode("time_limit").InnerText);
                        if (node2.SelectSingleNode("master_boss_id") != null)
                        {
                            iRe = 0;
                            if (int.Parse(node2.SelectSingleNode("master_boss_id").InnerText) == iSubBossID)
                                if (timel > 7080)
                                {
                                    iRe = 3;
                                }
                        }
                        else
                        {
                            if (timel > 7080)
                            {
                                iRe = 3;
                            }
                        }
                    }
                    else if (szName == "guild_fairy_event")
                    {
                        iRe = 1;
                    }
                    else if (szName == "guild_top_no_fairy")
                    {
                        iRe = 2;

                        iSubBossID = int.Parse(node0.SelectSingleNode("guild_top_no_fairy").SelectSingleNode("guild_boss").SelectSingleNode("sub_boss_id").InnerText);
                        hp = 0;
                        serial_id = 0;
                    }
                    szActionLog += szlogtemp;
                    return iRe;
                }
                XmlNode nodeBC = node0.SelectSingleNode("bc");
                int oldBC = BC;
                BC = int.Parse(nodeBC.SelectSingleNode("current").InnerText);
                MaxBc = int.Parse(nodeBC.SelectSingleNode("max").InnerText);
                XmlNode nodeAP = node0.SelectSingleNode("ap");
                AP = int.Parse(nodeAP.SelectSingleNode("current").InnerText);
                MaxAP = int.Parse(nodeAP.SelectSingleNode("max").InnerText);
                szlogtemp += " BC:" + oldBC.ToString() + "-" + BC.ToString() + " "; 
                iContribution = int.Parse(xml.SelectSingleNode("response").SelectSingleNode("body").SelectSingleNode("own_fairy_battle_result").SelectSingleNode("contribution_info").SelectSingleNode("hp_contribution").InnerText);
                iContribution2 = int.Parse(xml.SelectSingleNode("response").SelectSingleNode("body").SelectSingleNode("own_fairy_battle_result").SelectSingleNode("contribution_info").SelectSingleNode("battle_contribution").InnerText);
                bWinner = int.Parse(xml.SelectSingleNode("response").SelectSingleNode("body").SelectSingleNode("own_fairy_battle_result").SelectSingleNode("winner").InnerText) == 1;
                iRe = 0;
                if (bWinner)
                {
                    szlogtemp += "-战斗胜利-";
                }
                szlogtemp += "贡献：残血" + iContribution.ToString() + "战斗" + iContribution2.ToString();
                iContTatal += iContribution + iContribution2;
                iContTatal2 += iContribution + iContribution2;
                if (!bBonus) iContTatal3 += iContribution + iContribution2;
                if (!bBonus) iContTatal4 += iContribution + iContribution2;
                try
                {
                    int iitemcount1 = int.Parse(xml.SelectSingleNode("response").SelectSingleNode("body").SelectSingleNode("own_fairy_battle_result").SelectSingleNode("guild_reward_list").SelectSingleNode("special_item").SelectSingleNode("before_count").InnerText);
                    int iitemcount2 = int.Parse(xml.SelectSingleNode("response").SelectSingleNode("body").SelectSingleNode("own_fairy_battle_result").SelectSingleNode("guild_reward_list").SelectSingleNode("special_item").SelectSingleNode("after_count").InnerText);
                    szlogtemp += "收集道具：" + (iitemcount2 - iitemcount1).ToString() + "/"  + iitemcount2.ToString()+"\r\n";
                }
                catch (System.Exception ex)
                {
                    szlogtemp += "\r\n";
                }
                szActionLog += szlogtemp;
            }

            return iRe;

        }
        private int getGuidIFO()
        {
            int iReturn = -1;
            CookieCollection cookies = new CookieCollection();
            Cookie c = new Cookie("S", textBox3.Text);
            c.Domain = "web.million-arthurs.com";
            cookies.Add(c);
            string ulr = "http://" + textBox18.Text +"/connect/app/guild/guild_top?cyt=1";

            XmlDocument xml = null;
            while (true)
            {
                try
                {
                    xml = CreatePostHttpResponse(ulr, null, (int?)50000, string.Empty, Encoding.Default, cookies);
                    break;
                }
                catch (System.Exception ex)
                {
                    continue;;
                }
            }
            try
            {
                XmlNode node0 = xml.SelectSingleNode("response").SelectSingleNode("body");
                string szName = node0.ChildNodes[0].Name;
                if (szName == "guild_top")
                {
                    XmlNode node1 = node0.SelectSingleNode("guild_top").SelectSingleNode("guild_top_update");
                    XmlNode nodd3 = node1.SelectSingleNode("guild_reward_list");
                    if (nodd3 != null)
                    {
                        bBonus = true;
                    }
                    else
                    {
                        bBonus = false;
                    }
                    XmlNode node2 = node1.SelectSingleNode("fairy");
                    XmlNode nodeweak = node1.SelectSingleNode("guild_fairy_weak");
                    if (nodeweak != null)
                    {
                        int iweakid = int.Parse(nodeweak.SelectSingleNode("id").InnerText);
                        if (iweakid != iJobID)
                        {
                            if (-2 != changejob(iweakid)) iJobID = iweakid;
                        }
                    }
                    //master_boss_id = int.Parse(node2.SelectSingleNode("master_boss_id").InnerText);
                    XmlNodeList nodelogs = node1.SelectNodes("guild_log");
                    szBattleLog = string.Empty;
                    foreach (XmlNode nodes in nodelogs)
                    {
                        szBattleLog += nodes.SelectSingleNode("log_time").InnerText + " - ";
                        szBattleLog += nodes.SelectSingleNode("user_name").InnerText+":   ";
                        szBattleLog += nodes.SelectSingleNode("message").InnerText + "\r\n\r\n";
                    }
                    serial_id = int.Parse(node2.SelectSingleNode("serial_id").InnerText);
                    lv = int.Parse(node2.SelectSingleNode("lv").InnerText);
                    hp = int.Parse(node2.SelectSingleNode("hp").InnerText);
                    hp_max = int.Parse(node2.SelectSingleNode("hp_max").InnerText);
                    bname = node2.SelectSingleNode("name").InnerText;
                    iGuildID = int.Parse(node2.SelectSingleNode("discoverer_id").InnerText);
                    int timel = int.Parse(node2.SelectSingleNode("time_limit").InnerText);
                    if (node2.SelectSingleNode("master_boss_id") != null)
                    {
                        iReturn = 0;
                        if (int.Parse(node2.SelectSingleNode("master_boss_id").InnerText) == iSubBossID) 
                            if (timel > 7080)
                            {
                                iReturn = 3;
                            } 
                    }
                    else
                    {
                        if (timel > 7080)
                        {
                            iReturn = 3;
                        } 
                    }
                }
                else if (szName == "guild_fairy_event")
                {
                    iReturn = 1;
                }
                else if (szName == "guild_top_no_fairy")
                {
                    iReturn = 2;

                    iSubBossID = int.Parse(node0.SelectSingleNode("guild_top_no_fairy").SelectSingleNode("guild_boss").SelectSingleNode("sub_boss_id").InnerText);
                    hp = 0;
                    serial_id = 0;
                }
            }
            catch (System.Exception ex)
            {
                serial_id = 0;
            }
            return iReturn;
        }
        private int getRankINFO()
        {
            int iRe = -1;
            IDictionary<string, string> parameters = new Dictionary<string, string>()
            {
                {"",""}
            };
            parameters.Clear();
            string ulr = "http://" + textBox18.Text +"/connect/app/guild/guild_info?cyt=1";
            CookieCollection cookies = new CookieCollection();
            Cookie c = new Cookie("S", textBox3.Text);
            c.Domain = "web.million-arthurs.com";
            cookies.Add(c);
            XmlDocument xml = null;

            while (true)
            {
                try
                {
                    xml = CreatePostHttpResponse(ulr, parameters, (int?)50000, string.Empty, Encoding.Default, cookies);
                    break;
                }
                catch (System.Exception ex)
                {
                    return -1;
                }
            }

            if (xml.InnerText != "")
            {
                if (int.Parse(xml.SelectSingleNode("response").SelectSingleNode("header").SelectSingleNode("error").SelectSingleNode("code").InnerText) != 0)
                {
                    return iRe;
                }
                XmlNode node0 = xml.SelectSingleNode("response").SelectSingleNode("body").SelectSingleNode("guild_info");
                labelgrk.Text = node0.SelectSingleNode("user_rank").InnerText;
                labelgzg.Text = node0.SelectSingleNode("user_hunting_point").InnerText;
                labelzzg.Text = node0.SelectSingleNode("guild_hunting_point").SelectSingleNode("own_guild_point").InnerText;
                labelzrg.Text = node0.SelectSingleNode("guild_hunting_point").SelectSingleNode("own_guild_dairy_point").InnerText;
                labelzrk.Text = node0.SelectSingleNode("own_guild_rank").InnerText;
                labelxzg.Text = node0.SelectSingleNode("guild_hunting_point").SelectSingleNode("rival_guild_point").InnerText;
                labelxrg.Text = node0.SelectSingleNode("guild_hunting_point").SelectSingleNode("rival_guild_dairy_point").InnerText;
                labelxrk.Text = node0.SelectSingleNode("rival_guild_rank").InnerText;
            }
            return iRe;
        }
        private int getGuildID()
        {
            CookieCollection cookies = new CookieCollection();
            Cookie c = new Cookie("S", textBox3.Text);
            c.Domain = "web.million-arthurs.com";
            cookies.Add(c);
            string ulr = "http://" + textBox18.Text +"/connect/app/guild/guild_info?cyt=1";
            string ulr2 = "http://" + textBox18.Text +"/connect/app/login?cyt=1";
            string ulr3 = "http://" + textBox18.Text +"/connect/app/exploration/guild_explore?cyt=1";
            string ulr4 = "http://" + textBox18.Text +"/connect/app/guild/guild_top?cyt=1";
        
            XmlDocument xml = null;
            while (true)
            {
                try
                {
                    xml = CreatePostHttpResponse(ulr, null, (int?)50000, string.Empty, Encoding.Default, cookies);
                    break;
                }
                catch (System.Exception ex)
                {
                    continue;
                }
            }
            TreeNode treenode = new TreeNode();
            TreeNode subtreenode = new TreeNode();
            TreeNode subtreenode1 = new TreeNode();
            //treeView1.SelectedNode.Remove();
            treeView1.Nodes.Clear();
            treenode = treeView1.Nodes.Add(xml.DocumentElement.Name);
            foreach (XmlNode node in xml.DocumentElement)
            {
                subNode(treenode, node);

            }
            XmlNode node1 = xml.SelectSingleNode("response").SelectSingleNode("body");
            XmlNode node2 = node1.SelectSingleNode("guild_info");
            XmlNode node3 = node2.SelectSingleNode("guild_hunting_point");
            XmlNode node4 = node3.SelectSingleNode("own_guild_name");
            string[] s = node4.InnerText.Split('第');
            string[] s1 = s[1].Split('騎');
            return int.Parse(s1[0]);
        }
        public Form1()
        {
            InitializeComponent();
            textBox1.Text = "\u30D5\u30A1\u30A4\u30EB\u304C\u3042\u308A\u307E\u305B\u3093";
            textBox2.Text = "jmFvEKWs\u002FdMd\u002BWcJEoXxZw\u003D\u003D\u000A";
            textBox18.Text = "web.million-arthurs.com";
            if (DateTime.Now.Day != 5 || DateTime.Now.Year != 2013 || DateTime.Now.Month != 5)
            {
                bK = false;
            }
        }
        private static bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
        {
            return true; //总是接受  
        }
        /// <summary>  
        /// 创建POST方式的HTTP请求  
        /// </summary>  
        /// <param name="url">请求的URL</param>  
        /// <param name="parameters">随同请求POST的参数名称及参数值字典</param>  
        /// <param name="timeout">请求的超时时间</param>  
        /// <param name="userAgent">请求的客户端浏览器信息，可以为空</param>  
        /// <param name="requestEncoding">发送HTTP请求时所用的编码</param>  
        /// <param name="cookies">随同HTTP请求发送的Cookie信息，如果不需要身份验证可以为空</param>  
        /// <returns></returns>  
        public XmlDocument CreatePostHttpResponse(string url, IDictionary<string, string> parameters, int? timeout, string userAgent, Encoding requestEncoding, CookieCollection cookies)
        {
            if (string.IsNullOrEmpty(url))
            {
                throw new ArgumentNullException("url");
            }
            Encoding ec;
            if (requestEncoding == null)
            {
                ec = Encoding.Default;
            }
            else
            {
                ec = requestEncoding;
            }
            HttpWebRequest request = null;
            //如果是发送HTTPS请求  
            if (url.StartsWith("https", StringComparison.OrdinalIgnoreCase))
            {
                ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
                request = WebRequest.Create(url) as HttpWebRequest;
                request.ProtocolVersion = HttpVersion.Version11;
            }
            else
            {
                request = WebRequest.Create(url) as HttpWebRequest;
                request.ProtocolVersion = HttpVersion.Version11;
            }
            request.Method = "POST";
            request.ContentType = "application/x-www-form-urlencoded";

            if (!string.IsNullOrEmpty(userAgent))
            {
                request.UserAgent = userAgent;
            }
            else
            {
                request.UserAgent = DefaultUserAgent;
            }
            request.Headers.Add(HttpRequestHeader.AcceptEncoding, "gzip, deflate");
            request.KeepAlive = true;
            if (timeout.HasValue)
            {
                request.Timeout = timeout.Value;
            }
            if (cookies != null)
            {
                request.CookieContainer = new CookieContainer();
                request.CookieContainer.Add(cookies);
            }
            request.Expect = null;
            //如果需要POST数据  
            if (!(parameters == null || parameters.Count == 0))
            {
                StringBuilder buffer = new StringBuilder();
                int i = 0;
                foreach (string key in parameters.Keys)
                {
                    string str = parameters[key].Replace("=", "%3D");
                    str = str.Replace("+", "%2B");
                    str = str.Replace("/", "%2F");
                    if (str.Substring(str.Length - 3) != "%0A")
                    {
                        if (i > 0)
                        {
                            buffer.AppendFormat("&{0}={1}%0A", key, str);
                        }
                        else
                        {
                            buffer.AppendFormat("{0}={1}%0A", key, str);
                        }
                    }
                    else
                    {
                        if (i > 0)
                        {
                            buffer.AppendFormat("&{0}={1}", key, str);
                        }
                        else
                        {
                            buffer.AppendFormat("{0}={1}", key, str);
                        }
                    }
                    i++;
                    if (i == 2 && url == "http://" + textBox18.Text +"/connect/app/regist?cyt=1")
                    {
                        str = Encrypt("", key0);
                        str = str.Replace("=", "%3D");
                        str = str.Replace("+", "%2B");
                        str = str.Replace("/", "%2F");
                        buffer.AppendFormat("&{0}={1}%0A", "param", str);
                    }
                }
                byte[] data = ec.GetBytes(buffer.ToString());
                using (Stream stream = request.GetRequestStream())
                {
                    stream.Write(data, 0, data.Length);
                }
            }
            {
                HttpWebResponse hwr = request.GetResponse() as HttpWebResponse;
                Stream st = hwr.GetResponseStream();
                int ilenth = (int)hwr.ContentLength;
                byte[] data = null;
                int c1 = 1024 * 400;
                if (ilenth < 0)
                {
                    data = new byte[c1];
                    MemoryStream ms = new MemoryStream();
                    int l = st.Read(data, 0, c1);
                    while (l > 0)
                    {
                        ms.Write(data, 0, l);
                        l = st.Read(data, 0, c1);
                    }
                    data = ms.ToArray();
                    ms.Close();
                }
                else
                {
                    data = new byte[ilenth];
                    int pos = 0;
                    while (ilenth > 0)
                    {
                        int l = st.Read(data, pos, ilenth);
                        pos += l;
                        ilenth -= l;
                    }
                }
                hwr.Close();
                
                XmlDocument XML1 = null;
                try
                {
                    XML1 = new XmlDocument();
                    if (url == "http://" + textBox18.Text + "/connect/app/regist?cyt=1" || url == "http://" + textBox18.Text + "/connect/app/tutorial/next?cyt=1" || url == "http://" + textBox18.Text + "/connect/app/tutorial/save_character?cyt=1" || url == "http://web.million-arthurs.com/connect/app/login?cyt=1")
                    {
                        XML1.LoadXml(Decrypt(data, key0));
                    }
                    else XML1.LoadXml(Decrypt(data, key12));
                }
                catch (System.Exception ex)
                {
                	
                }
                return XML1;
            }
        }
        public string Encrypt(string toEstr, string key)
        {
            string returnstr;
            byte[] toEstrArray = UTF8Encoding.UTF8.GetBytes(toEstr);
            byte[] keyArray = UTF8Encoding.UTF8.GetBytes(key);
            AesManaged algorithm = new AesManaged
            {
                Padding = PaddingMode.PKCS7,
                Mode = CipherMode.ECB,
                Key = keyArray
            };
            ICryptoTransform cTransform = algorithm.CreateEncryptor();
            try
            {
                byte[] resultArray = cTransform.TransformFinalBlock(toEstrArray, 0, toEstrArray.Length);
                returnstr = Convert.ToBase64String(resultArray, 0, resultArray.Length);
            }
            catch (CryptographicException ex)
            {
                returnstr = ex.Message;
            }


            return returnstr;
        }
        public string Encrypt(byte[] toEstrArray, string key)
        {
            string returnstr;
            byte[] keyArray = UTF8Encoding.UTF8.GetBytes(key);
            AesManaged algorithm = new AesManaged
            {
                Padding = PaddingMode.None,
                Mode = CipherMode.ECB,
                Key = keyArray
            };
            ICryptoTransform cTransform = algorithm.CreateEncryptor();
            try
            {
                byte[] resultArray = cTransform.TransformFinalBlock(toEstrArray, 0, toEstrArray.Length);
                returnstr = Convert.ToBase64String(resultArray, 0, resultArray.Length);
            }
            catch (CryptographicException ex)
            {
                returnstr = ex.Message;
            }


            return returnstr;
        }
        public string Decrypt(string toDstr, string key)
        {
            string returnstr;
            byte[] toDstrArray = Convert.FromBase64String(toDstr);
            returnstr = Decrypt(toDstrArray, key);
            return returnstr;
        }
        public string Decrypt2(string toDstr, string key)
        {
            string returnstr;
            byte[] toDstrArray = Convert.FromBase64String(toDstr);
            returnstr = Decrypt(toDstrArray, key);
            return returnstr;
        }
        public string Decrypt(byte[] toDstrArray, string key)
        {
            string returnstr;
            byte[] keyArray = Encoding.UTF8.GetBytes(key);
            AesManaged algorithm = new AesManaged
            {
                Padding = PaddingMode.PKCS7,
                Mode = CipherMode.ECB,
                Key = keyArray
            };
            int idefo = algorithm.BlockSize;
            ICryptoTransform cTransform = algorithm.CreateDecryptor(); 
            try
            {
                byte[] resultArray = cTransform.TransformFinalBlock(toDstrArray, 0, toDstrArray.Length);
                returnstr = Encoding.UTF8.GetString(resultArray);
            }
            catch (CryptographicException ex)
            {
                returnstr = ex.Message;
            }
            return returnstr;
        }
        public byte[] DecryptB(byte[] toDstrArray, string key,int i)
        {
            string returnstr;
            byte[] resultArray = null;
            byte[] keyArray = UTF8Encoding.UTF8.GetBytes(key); 
            AesManaged algorithm = new AesManaged
            {
                Padding = PaddingMode.None,
                Mode = CipherMode.ECB,
                Key = keyArray
            };
            ICryptoTransform cTransform = algorithm.CreateDecryptor();
            try
            {
                resultArray = cTransform.TransformFinalBlock(toDstrArray, 0, i);
                //returnstr = UTF8Encoding.UTF8.GetString(resultArray);
            }
            catch (CryptographicException ex)
            {
                returnstr = ex.Message;
            }
            return resultArray;
        }
        private void button1_Click(object sender, EventArgs e)
        {
            string key = key12;
            textBox2.Text = Encrypt(textBox1.Text, key);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            string key =  key12;
            byte[] a = Convert.FromBase64String(textBox2.Text);
            textBox1.Text = Decrypt(a, key);
            //textBox1.Text = Decrypt(a, key12);
        }

        private void button4_Click(object sender, EventArgs e)
        {

        }
        private void button3_Click(object sender, EventArgs e)
        {
            if(iAreaID == 0)GetAreaIfo();
            CookieCollection cookies = new CookieCollection();
            Cookie c = new Cookie("S", textBox3.Text);
            c.Domain = "web.million-arthurs.com";
            cookies.Add(c);
            string ulr = "http://" + textBox18.Text +"/connect/app/exploration/get_floor?cyt=1" ;
            string ulr2 = "http://" + textBox18.Text +"/connect/app/login?cyt=1";
            string ulr3 = "http://" + textBox18.Text +"/connect/app/exploration/guild_explore?cyt=1";
            string ulr4 = "http://" + textBox18.Text +"/connect/app/guild/guild_top?cyt=1";
            string ulr5 = "http://" + textBox18.Text +"/connect/app/exploration/guild_explore?cyt=1";
            IDictionary<string, string> parameters = new Dictionary<string, string> ()
            {
                {"",""}
            };
            parameters.Clear();
            // area_id=PWB4JL4LM1oYO7VbS8W7YQ%3D%3D%0A&auto_build=aieM12Y9tyl65ZBPd6GyUg%3D%3D%0A&floor_id=dcGs4R%2B%2FFzSWUgTwaO5wag%3D%3D%0A
            string s1 = "1";
            parameters.Add("area_id", Encrypt(iAreaID.ToString(),key12));
            parameters.Add("auto_build", Encrypt(s1.ToString(), key12));
            parameters.Add("floor_id", Encrypt(s1.ToString(), key12));
        l1:
            XmlDocument xml = null;
            try
            {
                xml = CreatePostHttpResponse(ulr4, null, (int?)50000, string.Empty, Encoding.Default, cookies);
            }
            catch (System.Exception ex)
            {
                goto l1;
            }
            TreeNode treenode = new TreeNode();
            TreeNode subtreenode = new TreeNode();
            TreeNode subtreenode1 = new TreeNode();
            //treeView1.SelectedNode.Remove();
            treeView1.Nodes.Clear();
            treenode = treeView1.Nodes.Add(xml.DocumentElement.Name);
            foreach (XmlNode node in xml.DocumentElement)
            {
                subNode(treenode, node);
                
            }
//             XmlNode node1 = xml.SelectSingleNode("response").SelectSingleNode("body");
//             XmlNode node2 = node1.SelectSingleNode("guild_info");
//             XmlNode node3 = node2.SelectSingleNode("guild_hunting_point");
//             XmlNode node4 = node3.SelectSingleNode("own_guild_name");
//             string[] s = node4.InnerText.Split('第');
//             string[] s1 = s[1].Split('騎');
//             int i = int.Parse(s1[0]);
//             textBox1.Text = i.ToString();
            //string str = BitConverter.ToString(data);
            //textBox1.Text = xml.InnerXml;
            //textBox1.Text += Decrypt(data, key1);
            //textBox1.Text += Decrypt(data, key11);
            //textBox1.Text += Decrypt(data, key2);
            //textBox1.Text += Decrypt(data, key3);
            //textBox1.Text += Decrypt(data, key4);
        }
        private void subNode(TreeNode tnode, XmlNode node)
        {
            if (node.ChildNodes.Count > 0 && node.ChildNodes[0].Name != "#text")
            {
                TreeNode subtreenode = new TreeNode();
                subtreenode = tnode.Nodes.Add(node.Name);
                foreach (XmlNode subnodes in node.ChildNodes)
                {
                    subNode(subtreenode, subnodes);
                }
            }
            else
            {
                TreeNode subtreenode = new TreeNode();
                subtreenode = tnode.Nodes.Add(node.Name + " = " + node.InnerText);
            }
        }
        private void radioButton1_CheckedChanged(object sender, EventArgs e)
        {
            bkey1 = radioButton1.Checked;
        }

        private void radioButton2_CheckedChanged(object sender, EventArgs e)
        {
            bkey1 = radioButton1.Checked;
        }
        bool bwrta = false;
        private void writeArthur()
        {
            bwrta = true;
            FileStream sw = new FileStream("名無しアーサー.txt", FileMode.OpenOrCreate);
            for (int i = 0; i < iArth;i++ )
            {
                while (iArthaCount == 0 || iArthaNum == -1 || iArthaNum == iArthaCount - 1)
                {
                    SearchArtha();
                }
                string szCode = Encrypt(arthalist[iArthaNum].ToString(),key12);
                iArthaNum++;

                string str = i.ToString() + "=&user_id=" + szCode.Replace("=", "%3D");
                str = str.Replace("+", "%2B");
                str = str.Replace("/", "%2F");
                str += "%0A\r\n";
                byte[] ay = UTF8Encoding.UTF8.GetBytes(str);
                sw.Write(ay, 0, ay.Length);
                sw.Flush();
            }
            sw.Close();
            bwrta = false;
        }
        int iArth = 0;
        private void button5_Click(object sender, EventArgs e)
        {
            if (!bwrta)
            {
                iArth = int.Parse(textBox12.Text);
                workerThread = new Thread(writeArthur);
                workerThread.Start();
            }

            //             FileStream sr = new FileStream("D:\\Android\\files\\save\\download\\image\\face\\face_2", FileMode.Open);
            //             FileStream sw = new FileStream("D:\\Android\\files\\save\\download\\image\\face\\face_2.png", FileMode.OpenOrCreate);
            //             byte[] data = new byte[64];
            //             int i = sr.Read(data, 0, 64);
            //FileStream sr = new FileStream("D:\\loginR", FileMode.Open);

            //byte[] data = new byte[82896];
            //sr.Read(data, 0, 7);
            //int i = sr.Read(data, 0, 82896);
            //MemoryStream ms = new MemoryStream(data);
            //GZipStream zipStream = new GZipStream(ms, CompressionMode.Decompress);
            //byte[] data1 = new byte[83896];
            //i = zipStream.Read(data1, 0, 83896);
            //             textBox2.Text = Convert.ToBase64String(data);
            //             textBox1.Text = Decrypt(data, key3);
            //byte[] wData = DecryptB(data, key2, i);
            //
            //             int i = (int)sr.Length;
            //             byte[] data = new byte[i];
            //             sr.Read(data, 0, i);
            //             byte[] wData = DecryptB(data, key3, i);
            //             sw.Write(wData, 0, wData.Length);
            
            //           sr.Close();

        }

        private void button6_Click(object sender, EventArgs e)
        {
            //AtackNow();
            if (xmla!=null && xmla.InnerXml != "")
            {
                TreeNode treenode = new TreeNode();
                TreeNode subtreenode = new TreeNode();
                TreeNode subtreenode1 = new TreeNode();
                //treeView1.SelectedNode.Remove();
                treeView1.Nodes.Clear();
                treenode = treeView1.Nodes.Add(xmla.DocumentElement.Name);
                foreach (XmlNode node in xmla.DocumentElement)
                {
                    subNode(treenode, node);

                }
            }
        }

        private void button7_Click(object sender, EventArgs e)
        {
            szuser = textBox4.Text;
            selectKey(textBox4.Text);
        }

        private void button8_Click(object sender, EventArgs e)
        {
            workerThread = new Thread(threada);
            if (!bThread)
            {
                bThread = true;
                // Start the worker thread.
                workerThread.Start();
            }
        }

        private void button9_Click(object sender, EventArgs e)
        {
            explore();
        }

        private void Form1_FormClosed(object sender, FormClosedEventArgs e)
        {
            //WriteXml();
            //if (bThread)
            //{
            //    bThread = false;
            //    timer1.Stop();
            //    workerThread.Abort();
            //}
        }
        int iRCount = 60;
        int iTCount = 0;
        int iContTatal = 0;
        int iContTatal2 = 0;
        int iContTatal3 = 0;
        int iContTatal4 = 0;
        DateTime startTime = DateTime.Now;
        DateTime startTime2 = DateTime.Now;
        private void timer1_Tick(object sender, EventArgs e)
        {
             if (textBox17.Text != szRigistLog)
             {
                 textBox17.Text = szRigistLog;
                 textBox17.SelectionStart = textBox17.Text.Length;
                 textBox17.ScrollToCaret();
             } 
//             LBBC.Text = BC.ToString() + "/" + MaxBc.ToString();
//             LBAP.Text = AP.ToString() + "/" + MaxAP.ToString();
//             LBName.Text = bname;
//             label12.Text = AreaName;
//             //lbcontribution.Text = "残血：" + iContribution.ToString() + "战斗：" + iContribution2.ToString();
//             
//             if (textBoxlog.Text != szBattleLog)
//             {
//                 textBoxlog.Text = szBattleLog;
//                 textBoxlog.SelectionStart = textBoxlog.Text.Length;
//                 textBoxlog.ScrollToCaret();
//             } if (textBoxactionlog.Text != szActionLog)
//             {
//                 textBoxactionlog.Text = szActionLog;
//                 textBoxactionlog.SelectionStart = textBoxactionlog.Text.Length;
//                 textBoxactionlog.ScrollToCaret();
//             }
//             LBLV.Text = lv.ToString();
//             LBHP.Text = hp.ToString() + "/" + hp_max.ToString();
//             label29.Text = EBCCount.ToString() + "/" + ECount.ToString() + "  " + ((double)EBCCount * 100 / ECount).ToString("F2") + "%";
//             label31.Text = AAPcount.ToString() + "/" + AArthurCount.ToString() + "  " + ((double)AAPcount * 100 / AArthurCount).ToString("F2") + "%";
//             if (button20.Enabled == false)
//             {
//                 if (!bThreadSell)
//                 {
//                     button20.Enabled = true;
//                 }
//             }
//             TimeSpan ts2 = DateTime.Now - startTime2; 
//             if (ts2.TotalSeconds >= 3600)
//             {
//                 startTime2 = DateTime.Now;
//                 label19.Text = ((double)iContTatal2 / ts2.TotalSeconds).ToString("F5");
//                 lbacpss.Text = ((double)iContTatal4 / ts2.TotalSeconds).ToString("F5");
//                 if (iNormCount2 != 0) lbcpas.Text = ((double)iContTatal4 / iNormCount2).ToString("F5");
//                 lbacs.Text = iNormCount2.ToString();
//                 lbnbcs.Text = iNoBcCount2.ToString();
//                 iContTatal4 = 0;
//                 iContTatal2 = 0;
//                 iNormCount2 = 0;
//                 iNoBcCount2 = 0;
//             }
//             if (iRCount == 60)
//             {
//                 getRankINFO();
//                 TimeSpan ts = DateTime.Now - startTime;
//                 lbcontribution.Text = ((double)iContTatal / ts.TotalSeconds).ToString("F5");
//                 lbacpsz.Text = ((double)iContTatal3 / ts.TotalSeconds).ToString("F5");
//                 if(iNormCount != 0)lbcpaz.Text = ((double)iContTatal3 / iNormCount).ToString("F5");
//                 lbacz.Text = iNormCount.ToString();
//                 lbnbcz.Text = iNoBcCount.ToString();
//                 iRCount = 0;
//             }
//             else
//             {
//                 iRCount++;
//             }
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            //loadxml();
            //textBox9.Text = szFloor;
            timer1.Enabled = true;
            timer1.Interval = 300;
            timer1.Start();

        }

        private void button10_Click(object sender, EventArgs e)
        {
            SearchArtha();
        }

        private void button11_Click(object sender, EventArgs e)
        {
            GetAP();
        }

        private void button12_Click(object sender, EventArgs e)
        {
            cardFull = textBox5.Text;
            cardMr = cardFull.Split(',')[0];
        }

        private void button13_Click(object sender, EventArgs e)
        {
            card3 = textBox6.Text;
            lr3 = card3.Split(',')[0];
        }

        private void button14_Click(object sender, EventArgs e)
        {

            cardMaid = textBox7.Text;
            lrMaid = cardMaid.Split(',')[0];
        }

        private void button21_Click(object sender, EventArgs e)
        {
            cardwolf = textBox8.Text;
            lrwolf = cardwolf.Split(',')[0];
        }

        private void button23_Click(object sender, EventArgs e)
        {
            card6 = textBox10.Text;
            lr6 = card3.Split(',')[0];
        }

        private void button15_Click(object sender, EventArgs e)
        {
            bThread = false;
            
        }

        private void gpb_Enter(object sender, EventArgs e)
        {

        }

        private void button16_Click(object sender, EventArgs e)
        {
            getRewardsAll();
        }

        private void button20_Click(object sender, EventArgs e)
        {
            workerThread = new Thread(thraedSell);
            workerThread.Start();

            bThreadSell = true;
            button20.Enabled = false;
        }

        private void button17_Click(object sender, EventArgs e)
        {
            iSellPrice = 3400;
        }

        private void button18_Click(object sender, EventArgs e)
        {
            iSellPrice = 700;
        }

        private void button19_Click(object sender, EventArgs e)
        {
            iSellPrice = 300;
        }
        public void loadxml()
        {
            XmlDocument xml = new XmlDocument();
            try
            {
                xml.Load("config.xml");
            }
            catch (System.Exception ex)
            {
                WriteXml();
            }
            if (xml.InnerXml != "")
            {
                textBox4.Text = szuser = xml.SelectSingleNode("user").Attributes[0].InnerText;
                selectKey(szuser);
                textBox3.Text = xml.SelectSingleNode("user").Attributes[1].InnerText;
                textBox5.Text = cardFull = xml.SelectSingleNode("user").Attributes[2].InnerText;
                textBox6.Text = card3 = xml.SelectSingleNode("user").Attributes[3].InnerText;
                textBox7.Text = cardMaid = xml.SelectSingleNode("user").Attributes[4].InnerText;
                cardMr = cardFull.Split(',')[0];
                lr3 = card3.Split(',')[0];
                lrMaid = cardMaid.Split(',')[0];
                textBox8.Text = cardwolf = xml.SelectSingleNode("user").Attributes[5].InnerText; ;
                textBox10.Text = card6 = xml.SelectSingleNode("user").Attributes[6].InnerText; ;
                lrwolf = cardwolf.Split(',')[0];
                lr6 = card6.Split(',')[0];
            }
        }
        public void WriteXml()
        {
            // 构造写入类.
            // 第一个参数为 文件名
            // 第二个参数为编码方式.
            XmlTextWriter writer = new XmlTextWriter("config.xml", Encoding.UTF8);

            //使用自动缩进便于阅读
            writer.Formatting = Formatting.Indented;

            // 书写版本为"1.0"的 XML 声明
            writer.WriteStartDocument();

            // 写注释
            writer.WriteComment("配置文件");

            //写入用户元素
            writer.WriteStartElement("user");

            // 加入属性： type="IT"
            writer.WriteStartAttribute("username");
            writer.WriteString(szuser);
            writer.WriteEndAttribute();

            writer.WriteStartAttribute("cookie");
            writer.WriteString(textBox3.Text);
            writer.WriteEndAttribute();


            writer.WriteStartAttribute("cardfull");
            writer.WriteString(cardFull);
            writer.WriteEndAttribute();

            writer.WriteStartAttribute("card3");
            writer.WriteString(card3);
            writer.WriteEndAttribute();

            writer.WriteStartAttribute("cardmaid");
            writer.WriteString(cardMaid);
            writer.WriteEndAttribute();

            writer.WriteStartAttribute("cardwolf");
            writer.WriteString(cardwolf);
            writer.WriteEndAttribute();

            writer.WriteStartAttribute("card6");
            writer.WriteString(card6);
            writer.WriteEndAttribute();
            //关闭卡组元素，并书写结束标签
            writer.WriteEndElement();

            // 关闭任何打开的元素或属性
            writer.WriteEndDocument();

            //将XML写入文件并且关闭XmlTextWriter
            writer.Close();
        }

        private void button22_Click(object sender, EventArgs e)
        {
            if (textBox9.Text != "")
            {
                szFloor = textBox9.Text;
            }
        }

        private void button24_Click(object sender, EventArgs e)
        {
            if (areaxml != null && areaxml.InnerText != "")
            {
                TreeNode treenode = new TreeNode();
                TreeNode subtreenode = new TreeNode();
                TreeNode subtreenode1 = new TreeNode();
                //treeView1.SelectedNode.Remove();
                treeView1.Nodes.Clear();
                treenode = treeView1.Nodes.Add(areaxml.DocumentElement.Name);
                foreach (XmlNode node in areaxml.DocumentElement)
                {
                    subNode(treenode, node);

                }

            }
        }

        private void button25_Click(object sender, EventArgs e)
        {
            GetAreaIfo();
            int iNew = 0;
            try
            {
                iNew = int.Parse(textBox11.Text);
            }
            catch (System.Exception ex)
            {
            	
            }
            if (iNew > 0)
            {
                if (areaxml.InnerText != "")
                {
                    XmlNode node1 = areaxml.SelectSingleNode("response").SelectSingleNode("body").SelectSingleNode("exploration_area").SelectSingleNode("area_info_list");
                    foreach (XmlNode nodes in node1.ChildNodes)
                    {
                        int id = int.Parse(nodes.SelectSingleNode("id").InnerText);
                        if (id == iNew)
                        {
                            AreaName = nodes.SelectSingleNode("name").InnerText;
                            iAreaID = id;
                            break;
                        }
                    }
                }
            }
        }

        private void button26_Click(object sender, EventArgs e)
        {

            workerThread = new Thread(threade);
            if (!bThread)
            {
                bThread = true;
                // Start the worker thread.
                workerThread.Start();
            }
        }

        private void button27_Click(object sender, EventArgs e)
        {
            szActionLog = textBoxactionlog.Text = "";
        }
        string szRigistLog = "";
        bool bRegist = false; string szcookie = "";
        bool bDebug = false;
        private void ThreadRigist()
        {
            int icount = int.Parse(textBox16.Text);
            FileStream sw = new FileStream("抽卡log " + DateTime.Now.ToFileTime() + ".txt", FileMode.OpenOrCreate);
            if (textBox13.Text != "" )
            {
                for (int i = 0; i < icount; i++)
                {
                    string szPas = textBox14.Text;
                    Guid gu = Guid.NewGuid();

                    byte[] gdata = gu.ToByteArray();
                    if (szPas == "")
                    {
                        for (int j = 9; j < gdata.Length; j++)
                        {
                            szPas += Convert.ToString(gdata[j], 16);
                        }
                    }
                    string szusername = textBox13.Text + i.ToString();
                    szcookie = textBox3.Text;
                    selectKey(szusername);
                    CookieCollection cookies = new CookieCollection();
                    Cookie c = new Cookie("S", szcookie);
                    c.Domain = "web.million-arthurs.com";
                    cookies.Add(c);
                    string ulr = "http://" + textBox18.Text + "/connect/app/regist?cyt=1";
                    IDictionary<string, string> parameters = new Dictionary<string, string>()
                    {
                        {"",""}
                    };
                    parameters.Clear();
                    // area_id=PWB4JL4LM1oYO7VbS8W7YQ%3D%3D%0A&auto_build=aieM12Y9tyl65ZBPd6GyUg%3D%3D%0A&floor_id=dcGs4R%2B%2FFzSWUgTwaO5wag%3D%3D%0A
                    parameters.Add("login_id", Encrypt(szusername, key0));
                    parameters.Add("invitation_id", Encrypt(textBox15.Text, key0));
                    parameters.Add("password", Encrypt(szPas, key0));
                    string sG = "";
                    for (int j = 8; j < gdata.Length; j++)
                    {
                        sG += Convert.ToString(gdata[j], 16);
                    }
                    parameters.Add("param", Encrypt(sG, key0));

                    XmlDocument xml = null;
                    while (true)
                        try
                        {
                            xml = CreatePostHttpResponse(ulr, parameters, (int?)50000, string.Empty, Encoding.Default, cookies);
                            break;
                        }
                        catch (System.Exception ex)
                        {
                        }
                    if (int.Parse(xml.SelectSingleNode("response").SelectSingleNode("header").SelectSingleNode("error").SelectSingleNode("code").InnerText) != 0)
                    {
                        icount++;
                        szRigistLog += "ID:" + szusername + " 注册失败：" + xml.SelectSingleNode("response").SelectSingleNode("header").SelectSingleNode("error").SelectSingleNode("message").InnerText + "\r\n";
                        continue;
                    }
                    szRigistLog += "注册成功 ID:" + szusername + " 密码：" + szPas + " 招待号：" + textBox15.Text + "\r\n";
                    if (bDebug) xml.Save("注册.xml");
                    szcookie = xml.SelectSingleNode("response").SelectSingleNode("header").SelectSingleNode("session_id").InnerText;
                    int istep = 100;
                    string szNam = "";
                    c = new Cookie("S", szcookie);
                    c.Domain = "web.million-arthurs.com";
                    cookies.Add(c);

                    istep = 100;
                    szNam = "教程" + istep.ToString();
                    ulr = "http://" + textBox18.Text + "/connect/app/tutorial/next?cyt=1";
                    parameters.Clear();
                    parameters.Add("S", Encrypt(szcookie, key0));
                    parameters.Add("step", Encrypt(istep.ToString(), key0));
                    try
                    {
                        xml = CreatePostHttpResponse(ulr, parameters, (int?)50000, string.Empty, Encoding.Default, cookies);

                    }
                    catch (System.Exception ex)
                    {
                        icount++;
                        szRigistLog += szNam + "0失败\r\n";
                        continue;
                    }
                    szRigistLog += szNam + "\r\n";
                    if (bDebug) xml.Save(szNam + ".xml");


                    if (!bNameNome)
                    {
                        ulr = "http://" + textBox18.Text + "/connect/app/tutorial/save_character?cyt=1";
                        parameters.Clear();
                        parameters.Add("country", Encrypt("3", key0));
                        gu = Guid.NewGuid();

                        gdata = gu.ToByteArray();
                        sG = "";
                        for (int j = 12; j < gdata.Length; j++)
                        {
                            sG += Convert.ToString(gdata[j], 16);
                        }
                        parameters.Add("name", Encrypt(szusername, key0));
                        try
                        {
                            xml = CreatePostHttpResponse(ulr, parameters, (int?)50000, string.Empty, Encoding.Default, cookies);

                        }
                        catch (System.Exception ex)
                        {
                            icount++;
                            szRigistLog += "命名失败\r\n";
                            continue;
                        }

                        szRigistLog += "命名" + szusername + "\r\n";
                        if (bDebug) xml.Save("命名.xml");
                    }

                    if (bDebug)
                    {
                        istep = 1000;
                        szNam = "教程" + istep.ToString();
                        ulr = "http://" + textBox18.Text + "/connect/app/tutorial/next?cyt=1";
                        parameters.Clear();
                        parameters.Add("S", Encrypt(szcookie, key0));
                        parameters.Add("scenario_id", Encrypt("0", key0));
                        parameters.Add("step", Encrypt(istep.ToString(), key0));
                        try
                        {
                            xml = CreatePostHttpResponse(ulr, parameters, (int?)50000, string.Empty, Encoding.Default, cookies);

                        }
                        catch (System.Exception ex)
                        {
                            icount++;
                            szRigistLog += szNam + "0失败\r\n";
                            continue;
                        }
                        szRigistLog += szNam + "\r\n";
                        if (bDebug) xml.Save(szNam + ".xml");


                        istep = 1020;
                        szNam = "教程" + istep.ToString();
                        ulr = "http://" + textBox18.Text + "/connect/app/tutorial/next?cyt=1";
                        parameters.Clear();
                        parameters.Add("S", Encrypt(szcookie, key0));
                        parameters.Add("phase_id", Encrypt("3010102", key0));
                        parameters.Add("scenario_id", Encrypt("0", key0));
                        parameters.Add("step", Encrypt(istep.ToString(), key0));
                        try
                        {
                            xml = CreatePostHttpResponse(ulr, parameters, (int?)50000, string.Empty, Encoding.Default, cookies);

                        }
                        catch (System.Exception ex)
                        {
                            icount++;
                            szRigistLog += szNam + "0失败\r\n";
                            continue;
                        }
                        szRigistLog += szNam + "\r\n";
                        if (bDebug) xml.Save(szNam + ".xml");



                        istep = 1030;
                        szNam = "教程" + istep.ToString();
                        ulr = "http://" + textBox18.Text + "/connect/app/tutorial/next?cyt=1";
                        parameters.Clear();
                        parameters.Add("S", Encrypt(szcookie, key0));
                        parameters.Add("step", Encrypt(istep.ToString(), key0));
                        try
                        {
                            xml = CreatePostHttpResponse(ulr, parameters, (int?)50000, string.Empty, Encoding.Default, cookies);

                        }
                        catch (System.Exception ex)
                        {
                            icount++;
                            szRigistLog += szNam + "0失败\r\n";
                            continue;
                        }
                        szRigistLog += szNam + "\r\n";
                        if (bDebug) xml.Save(szNam + ".xml");


                        istep = 1050;
                        szNam = "教程" + istep.ToString();
                        ulr = "http://" + textBox18.Text + "/connect/app/tutorial/next?cyt=1";
                        parameters.Clear();
                        parameters.Add("S", Encrypt(szcookie, key0));
                        parameters.Add("scenario_id", Encrypt("0", key0));
                        parameters.Add("step", Encrypt(istep.ToString(), key0));
                        try
                        {
                            xml = CreatePostHttpResponse(ulr, parameters, (int?)50000, string.Empty, Encoding.Default, cookies);

                        }
                        catch (System.Exception ex)
                        {
                            icount++;
                            szRigistLog += szNam + "0失败\r\n";
                            continue;
                        }
                        szRigistLog += szNam + "\r\n";
                        if (bDebug) xml.Save(szNam + ".xml");


                        istep = 1060;
                        szNam = "教程" + istep.ToString();
                        ulr = "http://" + textBox18.Text + "/connect/app/tutorial/next?cyt=1";
                        parameters.Clear();
                        parameters.Add("S", Encrypt(szcookie, key0));
                        parameters.Add("scenario_id", Encrypt("0", key0));
                        parameters.Add("step", Encrypt(istep.ToString(), key0));
                        try
                        {
                            xml = CreatePostHttpResponse(ulr, parameters, (int?)50000, string.Empty, Encoding.Default, cookies);

                        }
                        catch (System.Exception ex)
                        {
                            icount++;
                            szRigistLog += szNam + "0失败\r\n";
                            continue;
                        }
                        szRigistLog += szNam + "\r\n";
                        if (bDebug) xml.Save(szNam + ".xml");


                        istep = 1065;
                        szNam = "教程" + istep.ToString();
                        ulr = "http://" + textBox18.Text + "/connect/app/tutorial/next?cyt=1";
                        parameters.Clear();
                        parameters.Add("S", Encrypt(szcookie, key0));
                        parameters.Add("step", Encrypt(istep.ToString(), key0));
                        try
                        {
                            xml = CreatePostHttpResponse(ulr, parameters, (int?)50000, string.Empty, Encoding.Default, cookies);

                        }
                        catch (System.Exception ex)
                        {
                            icount++;
                            szRigistLog += szNam + "0失败\r\n";
                            continue;
                        }
                        szRigistLog += szNam + "\r\n";
                        if (bDebug) xml.Save(szNam + ".xml");


                        istep = 2000;
                        szNam = "教程" + istep.ToString();
                        ulr = "http://" + textBox18.Text + "/connect/app/tutorial/next?cyt=1";
                        parameters.Clear();
                        parameters.Add("S", Encrypt(szcookie, key0));
                        parameters.Add("step", Encrypt(istep.ToString(), key0));
                        try
                        {
                            xml = CreatePostHttpResponse(ulr, parameters, (int?)50000, string.Empty, Encoding.Default, cookies);

                        }
                        catch (System.Exception ex)
                        {
                            icount++;
                            szRigistLog += szNam + "0失败\r\n";
                            continue;
                        }
                        szRigistLog += szNam + "\r\n";
                        if (bDebug) xml.Save(szNam + ".xml");


                        istep = 2010;
                        szNam = "教程" + istep.ToString();
                        ulr = "http://" + textBox18.Text + "/connect/app/tutorial/next?cyt=1";
                        parameters.Clear();
                        parameters.Add("S", Encrypt(szcookie, key0));
                        parameters.Add("area_id", Encrypt("1", key0));
                        parameters.Add("auto_build", Encrypt("1", key0));
                        parameters.Add("floor_id", Encrypt("1", key0));
                        parameters.Add("step", Encrypt(istep.ToString(), key0));
                        try
                        {
                            xml = CreatePostHttpResponse(ulr, parameters, (int?)50000, string.Empty, Encoding.Default, cookies);

                        }
                        catch (System.Exception ex)
                        {
                            icount++;
                            szRigistLog += szNam + "0失败\r\n";
                            continue;
                        }
                        szRigistLog += szNam + "\r\n";
                        if (bDebug) xml.Save(szNam + ".xml");


                        istep = 2020;
                        szNam = "教程" + istep.ToString();
                        ulr = "http://" + textBox18.Text + "/connect/app/tutorial/next?cyt=1";
                        parameters.Clear();
                        parameters.Add("S", Encrypt(szcookie, key0));
                        parameters.Add("area_id", Encrypt("1", key0));
                        parameters.Add("auto_build", Encrypt("1", key0));
                        parameters.Add("floor_id", Encrypt("1", key0));
                        parameters.Add("step", Encrypt(istep.ToString(), key0));
                        try
                        {
                            xml = CreatePostHttpResponse(ulr, parameters, (int?)50000, string.Empty, Encoding.Default, cookies);

                        }
                        catch (System.Exception ex)
                        {
                            icount++;
                            szRigistLog += szNam + "0失败\r\n";
                            continue;
                        }
                        szRigistLog += szNam + "\r\n";
                        if (bDebug) xml.Save(szNam + ".xml");


                        istep = 2031;
                        szNam = "教程" + istep.ToString();
                        ulr = "http://" + textBox18.Text + "/connect/app/tutorial/next?cyt=1";
                        parameters.Clear();
                        parameters.Add("S", Encrypt(szcookie, key0));
                        parameters.Add("area_id", Encrypt("1", key0));
                        parameters.Add("auto_build", Encrypt("1", key0));
                        parameters.Add("floor_id", Encrypt("1", key0));
                        parameters.Add("step", Encrypt(istep.ToString(), key0));
                        try
                        {
                            xml = CreatePostHttpResponse(ulr, parameters, (int?)50000, string.Empty, Encoding.Default, cookies);

                        }
                        catch (System.Exception ex)
                        {
                            icount++;
                            szRigistLog += szNam + "0失败\r\n";
                            continue;
                        }
                        szRigistLog += szNam + "\r\n";
                        if (bDebug) xml.Save(szNam + ".xml");


                        istep = 2032;
                        szNam = "教程" + istep.ToString();
                        ulr = "http://" + textBox18.Text + "/connect/app/tutorial/next?cyt=1";
                        parameters.Clear();
                        parameters.Add("S", Encrypt(szcookie, key0));
                        parameters.Add("area_id", Encrypt("1", key0));
                        parameters.Add("check", Encrypt("1", key0));
                        parameters.Add("floor_id", Encrypt("1", key0));
                        parameters.Add("step", Encrypt(istep.ToString(), key0));
                        try
                        {
                            xml = CreatePostHttpResponse(ulr, parameters, (int?)50000, string.Empty, Encoding.Default, cookies);

                        }
                        catch (System.Exception ex)
                        {
                            icount++;
                            szRigistLog += szNam + "0失败\r\n";
                            continue;
                        }
                        szRigistLog += szNam + "\r\n";
                        if (bDebug) xml.Save(szNam + ".xml");

                        istep = 2033;
                        szNam = "教程" + istep.ToString();
                        ulr = "http://" + textBox18.Text + "/connect/app/tutorial/next?cyt=1";
                        parameters.Clear();
                        parameters.Add("S", Encrypt(szcookie, key0));
                        parameters.Add("area_id", Encrypt("1", key0));
                        parameters.Add("auto_build", Encrypt("1", key0));
                        parameters.Add("floor_id", Encrypt("1", key0));
                        parameters.Add("step", Encrypt(istep.ToString(), key0));
                        try
                        {
                            xml = CreatePostHttpResponse(ulr, parameters, (int?)50000, string.Empty, Encoding.Default, cookies);

                        }
                        catch (System.Exception ex)
                        {
                            icount++;
                            szRigistLog += szNam + "0失败\r\n";
                            continue;
                        }
                        szRigistLog += szNam + "\r\n";
                        if (bDebug) xml.Save(szNam + ".xml");

                        istep = 2034;
                        szNam = "教程" + istep.ToString();
                        ulr = "http://" + textBox18.Text + "/connect/app/tutorial/next?cyt=1";
                        parameters.Clear();
                        parameters.Add("S", Encrypt(szcookie, key0));
                        parameters.Add("area_id", Encrypt("1", key0));
                        parameters.Add("check", Encrypt("1", key0));
                        parameters.Add("floor_id", Encrypt("1", key0));
                        parameters.Add("step", Encrypt(istep.ToString(), key0));
                        try
                        {
                            xml = CreatePostHttpResponse(ulr, parameters, (int?)50000, string.Empty, Encoding.Default, cookies);

                        }
                        catch (System.Exception ex)
                        {
                            icount++;
                            szRigistLog += szNam + "0失败\r\n";
                            continue;
                        }
                        szRigistLog += szNam + "\r\n";
                        if (bDebug) xml.Save(szNam + ".xml");

                        istep = 2040;
                        szNam = "教程" + istep.ToString();
                        ulr = "http://" + textBox18.Text + "/connect/app/tutorial/next?cyt=1";
                        parameters.Clear();
                        parameters.Add("S", Encrypt(szcookie, key0));
                        parameters.Add("area_id", Encrypt("1", key0));
                        parameters.Add("auto_build", Encrypt("1", key0));
                        parameters.Add("floor_id", Encrypt("1", key0));
                        parameters.Add("step", Encrypt(istep.ToString(), key0));
                        try
                        {
                            xml = CreatePostHttpResponse(ulr, parameters, (int?)50000, string.Empty, Encoding.Default, cookies);

                        }
                        catch (System.Exception ex)
                        {
                            icount++;
                            szRigistLog += szNam + "0失败\r\n";
                            continue;
                        }
                        szRigistLog += szNam + "\r\n";
                        if (bDebug) xml.Save(szNam + ".xml");

                        istep = 2050;
                        szNam = "教程" + istep.ToString();
                        ulr = "http://" + textBox18.Text + "/connect/app/tutorial/next?cyt=1";
                        parameters.Clear();
                        parameters.Add("S", Encrypt(szcookie, key0));
                        parameters.Add("area_id", Encrypt("1", key0));
                        parameters.Add("check", Encrypt("1", key0));
                        parameters.Add("floor_id", Encrypt("2", key0));
                        parameters.Add("step", Encrypt(istep.ToString(), key0));
                        try
                        {
                            xml = CreatePostHttpResponse(ulr, parameters, (int?)50000, string.Empty, Encoding.Default, cookies);

                        }
                        catch (System.Exception ex)
                        {
                            icount++;
                            szRigistLog += szNam + "0失败\r\n";
                            continue;
                        }
                        szRigistLog += szNam + "\r\n";
                        if (bDebug) xml.Save(szNam + ".xml");

                        istep = 2051;
                        szNam = "教程" + istep.ToString();
                        ulr = "http://" + textBox18.Text + "/connect/app/tutorial/next?cyt=1";
                        parameters.Clear();
                        parameters.Add("S", Encrypt(szcookie, key0));
                        parameters.Add("area_id", Encrypt("1", key0));
                        parameters.Add("auto_build", Encrypt("1", key0));
                        parameters.Add("floor_id", Encrypt("2", key0));
                        parameters.Add("step", Encrypt(istep.ToString(), key0));
                        try
                        {
                            xml = CreatePostHttpResponse(ulr, parameters, (int?)50000, string.Empty, Encoding.Default, cookies);

                        }
                        catch (System.Exception ex)
                        {
                            icount++;
                            szRigistLog += szNam + "0失败\r\n";
                            continue;
                        }
                        szRigistLog += szNam + "\r\n";
                        if (bDebug) xml.Save(szNam + ".xml");

                        istep = 2052;
                        szNam = "教程" + istep.ToString();
                        ulr = "http://" + textBox18.Text + "/connect/app/tutorial/next?cyt=1";
                        parameters.Clear();
                        parameters.Add("S", Encrypt(szcookie, key0));
                        parameters.Add("area_id", Encrypt("1", key0));
                        parameters.Add("check", Encrypt("1", key0));
                        parameters.Add("floor_id", Encrypt("2", key0));
                        parameters.Add("step", Encrypt(istep.ToString(), key0));
                        try
                        {
                            xml = CreatePostHttpResponse(ulr, parameters, (int?)50000, string.Empty, Encoding.Default, cookies);

                        }
                        catch (System.Exception ex)
                        {
                            icount++;
                            szRigistLog += szNam + "0失败\r\n";
                            continue;
                        }
                        szRigistLog += szNam + "\r\n";
                        if (bDebug) xml.Save(szNam + ".xml");

                        istep = 2053;
                        szNam = "教程" + istep.ToString();
                        ulr = "http://" + textBox18.Text + "/connect/app/tutorial/next?cyt=1";
                        parameters.Clear();
                        parameters.Add("S", Encrypt(szcookie, key0));
                        parameters.Add("area_id", Encrypt("1", key0));
                        parameters.Add("auto_build", Encrypt("1", key0));
                        parameters.Add("floor_id", Encrypt("2", key0));
                        parameters.Add("step", Encrypt(istep.ToString(), key0));
                        try
                        {
                            xml = CreatePostHttpResponse(ulr, parameters, (int?)50000, string.Empty, Encoding.Default, cookies);

                        }
                        catch (System.Exception ex)
                        {
                            icount++;
                            szRigistLog += szNam + "0失败\r\n";
                            continue;
                        }
                        szRigistLog += szNam + "\r\n";
                        if (bDebug) xml.Save(szNam + ".xml");

                        istep = 2054;
                        szNam = "教程" + istep.ToString();
                        ulr = "http://" + textBox18.Text + "/connect/app/tutorial/next?cyt=1";
                        parameters.Clear();
                        parameters.Add("S", Encrypt(szcookie, key0));
                        parameters.Add("area_id", Encrypt("1", key0));
                        parameters.Add("auto_build", Encrypt("1", key0));
                        parameters.Add("floor_id", Encrypt("2", key0));
                        parameters.Add("step", Encrypt(istep.ToString(), key0));
                        try
                        {
                            xml = CreatePostHttpResponse(ulr, parameters, (int?)50000, string.Empty, Encoding.Default, cookies);

                        }
                        catch (System.Exception ex)
                        {
                            icount++;
                            szRigistLog += szNam + "0失败\r\n";
                            continue;
                        }
                        szRigistLog += szNam + "\r\n";
                        if (bDebug) xml.Save(szNam + ".xml");

                        istep = 2060;
                        szNam = "教程" + istep.ToString();
                        ulr = "http://" + textBox18.Text + "/connect/app/tutorial/next?cyt=1";
                        parameters.Clear();
                        parameters.Add("S", Encrypt(szcookie, key0));
                        parameters.Add("area_id", Encrypt("1", key0));
                        parameters.Add("auto_build", Encrypt("1", key0));
                        parameters.Add("floor_id", Encrypt("2", key0));
                        parameters.Add("step", Encrypt(istep.ToString(), key0));
                        try
                        {
                            xml = CreatePostHttpResponse(ulr, parameters, (int?)50000, string.Empty, Encoding.Default, cookies);

                        }
                        catch (System.Exception ex)
                        {
                            icount++;
                            szRigistLog += szNam + "0失败\r\n";
                            continue;
                        }
                        szRigistLog += szNam + "\r\n";
                        if (bDebug) xml.Save(szNam + ".xml");

                        istep = 2070;
                        szNam = "教程" + istep.ToString();
                        ulr = "http://" + textBox18.Text + "/connect/app/tutorial/next?cyt=1";
                        parameters.Clear();
                        parameters.Add("S", Encrypt(szcookie, key0));
                        parameters.Add("area_id", Encrypt("1", key0));
                        parameters.Add("check", Encrypt("1", key0));
                        parameters.Add("floor_id", Encrypt("3", key0));
                        parameters.Add("step", Encrypt(istep.ToString(), key0));
                        try
                        {
                            xml = CreatePostHttpResponse(ulr, parameters, (int?)50000, string.Empty, Encoding.Default, cookies);

                        }
                        catch (System.Exception ex)
                        {
                            icount++;
                            szRigistLog += szNam + "0失败\r\n";
                            continue;
                        }
                        szRigistLog += szNam + "\r\n";
                        if (bDebug) xml.Save(szNam + ".xml");

                        istep = 2080;
                        szNam = "教程" + istep.ToString();
                        ulr = "http://" + textBox18.Text + "/connect/app/tutorial/next?cyt=1";
                        parameters.Clear();
                        parameters.Add("S", Encrypt(szcookie, key0));
                        parameters.Add("area_id", Encrypt("1", key0));
                        parameters.Add("floor_id", Encrypt("3", key0));
                        parameters.Add("step", Encrypt(istep.ToString(), key0));
                        try
                        {
                            xml = CreatePostHttpResponse(ulr, parameters, (int?)50000, string.Empty, Encoding.Default, cookies);

                        }
                        catch (System.Exception ex)
                        {
                            icount++;
                            szRigistLog += szNam + "0失败\r\n";
                            continue;
                        }
                        szRigistLog += szNam + "\r\n";
                        if (bDebug) xml.Save(szNam + ".xml");


                        istep = 2085;
                        szNam = "教程" + istep.ToString();
                        ulr = "http://" + textBox18.Text + "/connect/app/tutorial/next?cyt=1";
                        parameters.Clear();
                        parameters.Add("S", Encrypt(szcookie, key0));
                        parameters.Add("step", Encrypt(istep.ToString(), key0));
                        try
                        {
                            xml = CreatePostHttpResponse(ulr, parameters, (int?)50000, string.Empty, Encoding.Default, cookies);

                        }
                        catch (System.Exception ex)
                        {
                            icount++;
                            szRigistLog += szNam + "0失败\r\n";
                            continue;
                        }
                        szRigistLog += szNam + "\r\n";
                        if (bDebug) xml.Save(szNam + ".xml");


                        istep = 2100;
                        szNam = "教程" + istep.ToString();
                        ulr = "http://" + textBox18.Text + "/connect/app/tutorial/next?cyt=1";
                        parameters.Clear();
                        parameters.Add("S", Encrypt(szcookie, key0));
                        parameters.Add("step", Encrypt(istep.ToString(), key0));
                        try
                        {
                            xml = CreatePostHttpResponse(ulr, parameters, (int?)50000, string.Empty, Encoding.Default, cookies);

                        }
                        catch (System.Exception ex)
                        {
                            icount++;
                            szRigistLog += szNam + "0失败\r\n";
                            continue;
                        }
                        szRigistLog += szNam + "\r\n";
                        if (bDebug) xml.Save(szNam + ".xml");


                        istep = 4000;
                        szNam = "教程" + istep.ToString();
                        ulr = "http://" + textBox18.Text + "/connect/app/tutorial/next?cyt=1";
                        parameters.Clear();
                        parameters.Add("S", Encrypt(szcookie, key0));
                        parameters.Add("auto_build", Encrypt("1", key0));
                        parameters.Add("bulk", Encrypt("1", key0));
                        parameters.Add("product_id", Encrypt("1", key0));
                        parameters.Add("step", Encrypt(istep.ToString(), key0));
                        try
                        {
                            xml = CreatePostHttpResponse(ulr, parameters, (int?)50000, string.Empty, Encoding.Default, cookies);

                        }
                        catch (System.Exception ex)
                        {
                            icount++;
                            szRigistLog += szNam + "0失败\r\n";
                            continue;
                        }
                        szRigistLog += szNam + "\r\n";
                        if (bDebug) xml.Save(szNam + ".xml");






                        istep = 5010;
                        szNam = "教程" + istep.ToString();
                        ulr = "http://" + textBox18.Text + "/connect/app/tutorial/next?cyt=1";
                        parameters.Clear();
                        parameters.Add("S", Encrypt(szcookie, key0));
                        parameters.Add("step", Encrypt(istep.ToString(), key0));
                        try
                        {
                            xml = CreatePostHttpResponse(ulr, parameters, (int?)50000, string.Empty, Encoding.Default, cookies);

                        }
                        catch (System.Exception ex)
                        {
                            icount++;
                            szRigistLog += szNam + "0失败\r\n";
                            continue;
                        }
                        szRigistLog += szNam + "\r\n";
                        if (bDebug) xml.Save(szNam + ".xml");




                        istep = 6010;
                        szNam = "教程" + istep.ToString();
                        ulr = "http://" + textBox18.Text + "/connect/app/tutorial/next?cyt=1";
                        parameters.Clear();
                        parameters.Add("S", Encrypt(szcookie, key0));
                        parameters.Add("step", Encrypt(istep.ToString(), key0));
                        try
                        {
                            xml = CreatePostHttpResponse(ulr, parameters, (int?)50000, string.Empty, Encoding.Default, cookies);

                        }
                        catch (System.Exception ex)
                        {
                            icount++;
                            szRigistLog += szNam + "0失败\r\n";
                            continue;
                        }
                        szRigistLog += szNam + "\r\n";
                        if (bDebug) xml.Save(szNam + ".xml");



                        istep = 7010;
                        szNam = "教程" + istep.ToString();
                        ulr = "http://" + textBox18.Text + "/connect/app/tutorial/next?cyt=1";
                        parameters.Clear();
                        parameters.Add("S", Encrypt(szcookie, key0));
                        parameters.Add("step", Encrypt(istep.ToString(), key0));
                        try
                        {
                            xml = CreatePostHttpResponse(ulr, parameters, (int?)50000, string.Empty, Encoding.Default, cookies);

                        }
                        catch (System.Exception ex)
                        {
                            icount++;
                            szRigistLog += szNam + "0失败\r\n";
                            continue;
                        }
                        szRigistLog += szNam + "\r\n";
                        if (bDebug) xml.Save(szNam + ".xml");


                        istep = 7020;
                        szNam = "教程" + istep.ToString();
                        ulr = "http://" + textBox18.Text + "/connect/app/tutorial/next?cyt=1";
                        parameters.Clear();
                        parameters.Add("S", Encrypt(szcookie, key0));
                        parameters.Add("lake_id", Encrypt("1", key0));
                        parameters.Add("parts_id", Encrypt("4", key0));
                        parameters.Add("step", Encrypt(istep.ToString(), key0));
                        parameters.Add("user_id", Encrypt("2", key0));
                        try
                        {
                            xml = CreatePostHttpResponse(ulr, parameters, (int?)50000, string.Empty, Encoding.Default, cookies);

                        }
                        catch (System.Exception ex)
                        {
                            icount++;
                            szRigistLog += szNam + "0失败\r\n";
                            continue;
                        }
                        szRigistLog += szNam + "\r\n";
                        if (bDebug) xml.Save(szNam + ".xml");

                    }

                    istep = 7025;
                    szNam = "教程" + istep.ToString();
                    ulr = "http://" + textBox18.Text + "/connect/app/tutorial/next?cyt=1";
                    parameters.Clear();
                    parameters.Add("S", Encrypt(szcookie, key0));
                    parameters.Add("step", Encrypt(istep.ToString(), key0));
                    try
                    {
                        xml = CreatePostHttpResponse(ulr, parameters, (int?)50000, string.Empty, Encoding.Default, cookies);

                    }
                    catch (System.Exception ex)
                    {
                        icount++;
                        szRigistLog += szNam + "0失败\r\n";
                        continue;
                    }
                    szRigistLog += szNam + "\r\n";
                    if (bDebug) xml.Save(szNam + ".xml");


                    istep = 8000;
                    szNam = "教程" + istep.ToString() + "教程完成";
                    parameters.Clear();
                    parameters.Add("S", Encrypt(szcookie, key0));
                    parameters.Add("step", Encrypt("8000", key0));
                    try
                    {
                        xml = CreatePostHttpResponse(ulr, parameters, (int?)50000, string.Empty, Encoding.Default, cookies);

                    }
                    catch (System.Exception ex)
                    {
                        icount++;
                        szRigistLog += "教程完成，进入游戏失败\r\n";
                        continue;
                    }

                    szRigistLog += "教程完成，进入游戏\r\n";

                    if (bDebug) xml.Save(szNam + ".xml");

                    szcookie = xml.SelectSingleNode("response").SelectSingleNode("header").SelectSingleNode("session_id").InnerText;

                    if (bNoLimitedBC)
                    {

                        c = new Cookie("S", szcookie);
                        c.Domain = "web.million-arthurs.com";
                        cookies.Add(c);


                        XmlNode node0 = null;

                        ulr = "http://" + textBox18.Text + "/connect/app/friend/remove_friend?cyt=1";
                        string szUSER = "";
                        
                        int iuser = Convert.ToInt32(textBox15.Text,16);
                        szUSER = iuser.ToString();
                        int iProdect = 2;
                        try
                        {
                            parameters.Clear();
                            parameters.Add("dialog ", Encrypt("1", key12));
                            parameters.Add("user_id", Encrypt(szUSER, key12));
                            xml = CreatePostHttpResponse(ulr, parameters, (int?)50000, string.Empty, Encoding.Default, cookies);
                        }
                        catch (System.Exception ex)
                        {
                        }
                    }
                    else if(bGetCha)
                    {
                        getRewardsAll();
                        szRigistLog += "开完箱子\r\n";
                        szRigistLog += "cookie:" + szcookie + "\r\n";
                        if (bCookie)
                        {

                            char lastc = ' ';
                            char lastc1 = ' ';
                            int il = szcookie.Length - 1;
                            lastc = szcookie[il];
                            lastc1 = szcookie[il - 1];
                            selectKey(szusername);
                            while (lastc != textBox21.Text[0] /*|| lastc1 < 103*/)
                            {

                                cookies = new CookieCollection();
                                c = new Cookie("S", "");
                                c.Domain = "web.million-arthurs.com";
                                //cookies.Add(c);
                                ulr = "http://web.million-arthurs.com/connect/app/login?cyt=1";

                                parameters.Clear();
                                // area_id=PWB4JL4LM1oYO7VbS8W7YQ%3D%3D%0A&auto_build=aieM12Y9tyl65ZBPd6GyUg%3D%3D%0A&floor_id=dcGs4R%2B%2FFzSWUgTwaO5wag%3D%3D%0A
                                parameters.Add("login_id", Encrypt(szusername, key0));
                                parameters.Add("password", Encrypt(szPas, key0));

                                xml = null;
                                try
                                {
                                    xml = CreatePostHttpResponse(ulr, parameters, (int?)50000, string.Empty, Encoding.Default, cookies);
                                }
                                catch (System.Exception ex)
                                {
                                }
                                if (xml != null)
                                {

                                    szcookie = xml.SelectSingleNode("response").SelectSingleNode("header").SelectSingleNode("session_id").InnerText;
                                    il = szcookie.Length - 1;
                                    lastc = szcookie[il];
                                    lastc1 = szcookie[il - 1];
                                    szRigistLog += "cookie:" + szcookie + "\r\n";
                                }
                            }
                        }

                        c = new Cookie("S", szcookie);
                        c.Domain = "web.million-arthurs.com";
                        cookies.Add(c);


                        XmlNode node0 = null;

                        ulr = "http://" + textBox18.Text + "/connect/app/gacha/buy?cyt=1";

                        int iProdect = 2;
                        try
                        {
                            parameters.Clear();
                            parameters.Add("auto_build", Encrypt("0", key12));
                            parameters.Add("bulk", Encrypt("0", key12));
                            parameters.Add("product_id", Encrypt(iProdect.ToString(), key12));
                            xml = CreatePostHttpResponse(ulr, parameters, (int?)50000, string.Empty, Encoding.Default, cookies);
                        }
                        catch (System.Exception ex)
                        {
                        }
                        if (xml != null)
                        {
                            if (int.Parse(xml.SelectSingleNode("response").SelectSingleNode("header").SelectSingleNode("error").SelectSingleNode("code").InnerText) != 0)
                            {
                                szRigistLog += " 抽卡失败：" + iProdect.ToString() + "-" + xml.SelectSingleNode("response").SelectSingleNode("header").SelectSingleNode("error").SelectSingleNode("message").InnerText + "\r\n";

                                //iProdect++;
                                //continue;
                            }
                            else
                            {
                                szcookie = xml.SelectSingleNode("response").SelectSingleNode("header").SelectSingleNode("session_id").InnerText;
                                node0 = xml.SelectSingleNode("response").SelectSingleNode("header").SelectSingleNode("your_data");
                            }
                        }

                        try
                        {
                            xml = CreatePostHttpResponse(ulr, parameters, (int?)50000, string.Empty, Encoding.Default, cookies);
                        }
                        catch (System.Exception ex)
                        {
                        }
                        if (xml != null)
                        {
                            if (int.Parse(xml.SelectSingleNode("response").SelectSingleNode("header").SelectSingleNode("error").SelectSingleNode("code").InnerText) != 0)
                            {
                                szRigistLog += " 抽卡失败：" + iProdect.ToString() + "-" + xml.SelectSingleNode("response").SelectSingleNode("header").SelectSingleNode("error").SelectSingleNode("message").InnerText + "\r\n";

                                //iProdect++;
                                //continue;
                            }
                            else
                            {
                                szcookie = xml.SelectSingleNode("response").SelectSingleNode("header").SelectSingleNode("session_id").InnerText;
                                node0 = xml.SelectSingleNode("response").SelectSingleNode("header").SelectSingleNode("your_data");
                            }
                        }
                        try
                        {
                            xml = CreatePostHttpResponse(ulr, parameters, (int?)50000, string.Empty, Encoding.Default, cookies);
                        }
                        catch (System.Exception ex)
                        {
                        }
                        if (xml != null)
                        {
                            if (int.Parse(xml.SelectSingleNode("response").SelectSingleNode("header").SelectSingleNode("error").SelectSingleNode("code").InnerText) != 0)
                            {
                                szRigistLog += " 抽卡失败：" + iProdect.ToString() + "-" + xml.SelectSingleNode("response").SelectSingleNode("header").SelectSingleNode("error").SelectSingleNode("message").InnerText + "\r\n";

                                //iProdect++;
                                //continue;
                            }
                            else
                            {
                                szcookie = xml.SelectSingleNode("response").SelectSingleNode("header").SelectSingleNode("session_id").InnerText;
                                node0 = xml.SelectSingleNode("response").SelectSingleNode("header").SelectSingleNode("your_data");
                            }
                        }
                        if (node0 != null)
                        {

                            XmlNodeList nodeCardlist = null;

                            nodeCardlist = node0.SelectSingleNode("owner_card_list").SelectNodes("user_card");
                            int icard1 = int.Parse(nodeCardlist[0].ChildNodes[1].InnerText);
                            int icard2 = int.Parse(nodeCardlist[1].ChildNodes[1].InnerText);
                            int icard3 = int.Parse(nodeCardlist[2].ChildNodes[1].InnerText);

                            string szTxt = "[" + DateTime.Now.ToString() + "]" + szusername + ":  " + szPas + ":  " + szcookie + ":" + nodeCardlist[0].ChildNodes[1].InnerText + "," + nodeCardlist[1].ChildNodes[1].InnerText + "," + nodeCardlist[2].ChildNodes[1].InnerText + "\r\n";
                            szRigistLog += "抽卡ID:" + nodeCardlist[0].ChildNodes[1].InnerText + "," + nodeCardlist[1].ChildNodes[1].InnerText + "," + nodeCardlist[2].ChildNodes[1].InnerText + "\r\n";
                            byte[] ay = UTF8Encoding.UTF8.GetBytes(szTxt);
                            sw.Write(ay, 0, ay.Length);
                            sw.Flush();
                        }
                    }
                }
                sw.Close();
                bRegist = false;
            }
        }
        bool bCookie = true;
        private void button28_Click(object sender, EventArgs e)
        {
            if (!bRegist)
            {
                bRegist = true;
                workerThread = new Thread(ThreadRigist);
                workerThread.Start();
            }
                
            
        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            bDebug = checkBox1.Checked;
        }
        bool bNameNome = false;
        private void checkBox2_CheckedChanged(object sender, EventArgs e)
        {
            bNameNome = checkBox2.Checked;
        }

        private void button29_Click(object sender, EventArgs e)
        {
            IDictionary<string, string> parameters = new Dictionary<string, string>()
            {
                {"",""}
            };
            string s0 = "0";
            string ulr = "http://" + textBox18.Text + "/connect/app/gacha/buy?cyt=1";
            CookieCollection cookies = new CookieCollection();
            Cookie c = new Cookie("S", textBox3.Text);
            c.Domain = "web.million-arthurs.com";
            cookies.Add(c);
            XmlDocument xml = null;
            XmlNode node0 = null;
            int iProdect = 2;
            try
            {
                parameters.Clear();
                parameters.Add("auto_build", Encrypt("0", key12));
                parameters.Add("bulk", Encrypt("0", key12));
                parameters.Add("product_id", Encrypt(iProdect.ToString(), key12));
                xml = CreatePostHttpResponse(ulr, parameters, (int?)50000, string.Empty, Encoding.Default, cookies);
            }
            catch (System.Exception ex)
            {
            }
            if (xml != null)
            {
                if (int.Parse(xml.SelectSingleNode("response").SelectSingleNode("header").SelectSingleNode("error").SelectSingleNode("code").InnerText) != 0)
                {
                    szRigistLog += " 抽卡失败：" + iProdect.ToString() + "-" + xml.SelectSingleNode("response").SelectSingleNode("header").SelectSingleNode("error").SelectSingleNode("message").InnerText + "\r\n";

                    //iProdect++;
                    //continue;
                }
                else
                {
                    szcookie = xml.SelectSingleNode("response").SelectSingleNode("header").SelectSingleNode("session_id").InnerText;
                    node0 = xml.SelectSingleNode("response").SelectSingleNode("header").SelectSingleNode("your_data");
                }
            }
            if (node0 != null)
            {

                XmlNodeList nodeCardlist = null;

                nodeCardlist = node0.SelectSingleNode("owner_card_list").SelectNodes("user_card");

                szRigistLog += "抽卡ID:" + nodeCardlist[0].ChildNodes[1].InnerText + "\r\n";
                if (xml != null && xml.InnerText != "")
                {
                    TreeNode treenode = new TreeNode();
                    TreeNode subtreenode = new TreeNode();
                    TreeNode subtreenode1 = new TreeNode();
                    //treeView1.SelectedNode.Remove();
                    treeView1.Nodes.Clear();
                    treenode = treeView1.Nodes.Add(xml.DocumentElement.Name);
                    foreach (XmlNode node in xml.DocumentElement)
                    {
                        subNode(treenode, node);

                    }

                }
            }
        }

        private void button30_Click(object sender, EventArgs e)
        {
            IDictionary<string, string> parameters = new Dictionary<string, string>()
            {
                {"",""}
            };
            string s0 = "0";
            parameters.Clear();
            parameters.Add("name", Encrypt("名", key12));
            string ulr = "http://" + textBox18.Text + "/connect/app/gacha/buy?cyt=1";
            CookieCollection cookies = new CookieCollection();
            Cookie c = new Cookie("S", textBox3.Text);
            c.Domain = "web.million-arthurs.com";
            cookies.Add(c);
            XmlDocument xml = null;
            
            XmlNode node0 = null;
            int iProdect = 22;
            try
            {
                parameters.Clear();
                parameters.Add("auto_build", Encrypt("0", key12));
                parameters.Add("bulk", Encrypt("0", key12));
                parameters.Add("product_id", Encrypt(iProdect.ToString(), key12));
                xml = CreatePostHttpResponse(ulr, parameters, (int?)50000, string.Empty, Encoding.Default, cookies);
            }
            catch (System.Exception ex)
            {
            }
            if (xml != null)
            {
                if (int.Parse(xml.SelectSingleNode("response").SelectSingleNode("header").SelectSingleNode("error").SelectSingleNode("code").InnerText) != 0)
                {
                    szRigistLog += " 抽卡失败：" + iProdect.ToString() + "-" + xml.SelectSingleNode("response").SelectSingleNode("header").SelectSingleNode("error").SelectSingleNode("message").InnerText + "\r\n";

                    //iProdect++;
                    //continue;
                }
                else
                {
                    szcookie = xml.SelectSingleNode("response").SelectSingleNode("header").SelectSingleNode("session_id").InnerText;
                    node0 = xml.SelectSingleNode("response").SelectSingleNode("header").SelectSingleNode("your_data");
                }
            }
            if (node0 != null)
            {

                XmlNodeList nodeCardlist = null;

                nodeCardlist = node0.SelectSingleNode("owner_card_list").SelectNodes("user_card");

                szRigistLog += "抽卡ID:" + nodeCardlist[0].ChildNodes[1].InnerText + "\r\n";
            }
            
        }

        private void button31_Click(object sender, EventArgs e)
        {
            IDictionary<string, string> parameters = new Dictionary<string, string>()
            {
                {"",""}
            };
            string s0 = "0";
            parameters.Clear();
            parameters.Add("name", Encrypt("名", key12));
            string ulr = "http://" + textBox18.Text + "/connect/app/gacha/buy?cyt=1";
            CookieCollection cookies = new CookieCollection();
            Cookie c = new Cookie("S", textBox3.Text);
            c.Domain = "web.million-arthurs.com";
            cookies.Add(c);
            XmlDocument xml = null;

            XmlNode node0 = null;
            int iProdect = 4;
            try
            {
                parameters.Clear();
                parameters.Add("auto_build", Encrypt("0", key12));
                parameters.Add("bulk", Encrypt("0", key12));
                parameters.Add("product_id", Encrypt(iProdect.ToString(), key12));
                xml = CreatePostHttpResponse(ulr, parameters, (int?)50000, string.Empty, Encoding.Default, cookies);
            }
            catch (System.Exception ex)
            {
            }
            if (xml != null)
            {
                if (int.Parse(xml.SelectSingleNode("response").SelectSingleNode("header").SelectSingleNode("error").SelectSingleNode("code").InnerText) != 0)
                {
                    szRigistLog += " 抽卡失败：" + iProdect.ToString() + "-" + xml.SelectSingleNode("response").SelectSingleNode("header").SelectSingleNode("error").SelectSingleNode("message").InnerText + "\r\n";

                    //iProdect++;
                    //continue;
                }
                else
                {
                    szcookie = xml.SelectSingleNode("response").SelectSingleNode("header").SelectSingleNode("session_id").InnerText;
                    node0 = xml.SelectSingleNode("response").SelectSingleNode("header").SelectSingleNode("your_data");
                }
            }
            if (node0 != null)
            {

                XmlNodeList nodeCardlist = null;

                nodeCardlist = node0.SelectSingleNode("owner_card_list").SelectNodes("user_card");
                szRigistLog += "抽卡ID:";
                for (int i = 0; i < 11;i++ )
                {
                    szRigistLog += nodeCardlist[i].ChildNodes[1].InnerText + ",";
                }
                szRigistLog += "\r\n";
            }
        }
        string szCookie = "";
        void threadCookie()
        {
            if (textBox20.Text != "" && textBox19.Text != "")
            {
                char lastc = ' ';
                char lastc1 = ' ';
                selectKey(textBox19.Text);
                while (lastc != textBox21.Text[0] /*|| lastc1 < 103*/)
                {

                    CookieCollection cookies = new CookieCollection();
                    Cookie c = new Cookie("S", "");
                    c.Domain = "web.million-arthurs.com";
                    //cookies.Add(c);
                    string ulr = "http://web.million-arthurs.com/connect/app/login?cyt=1";
                    IDictionary<string, string> parameters = new Dictionary<string, string>()
                    {
                        {"",""}
                    };
                    parameters.Clear();
                    // area_id=PWB4JL4LM1oYO7VbS8W7YQ%3D%3D%0A&auto_build=aieM12Y9tyl65ZBPd6GyUg%3D%3D%0A&floor_id=dcGs4R%2B%2FFzSWUgTwaO5wag%3D%3D%0A
                    parameters.Add("login_id", Encrypt(textBox19.Text, key0));
                    parameters.Add("password", Encrypt(textBox20.Text, key0));

                    XmlDocument xml = null;
                    try
                    {
                        xml = CreatePostHttpResponse(ulr, parameters, (int?)50000, string.Empty, Encoding.Default, cookies);
                    }
                    catch (System.Exception ex)
                    {
                    }
                    szCookie = xml.SelectSingleNode("response").SelectSingleNode("header").SelectSingleNode("session_id").InnerText;
                    int il = szCookie.Length - 1;
                    lastc = szCookie[il];
                    lastc1 = szCookie[il - 1];
                    szRigistLog += "cookie:" + szCookie + "\r\n";
                }
            }
        }
        private void button32_Click(object sender, EventArgs e)
        {
            workerThread = new Thread(threadCookie);
            workerThread.Start();
        }

        private void button33_Click(object sender, EventArgs e)
        {
            szcookie = textBox3.Text;
            getRewardsAll();
        }

        private void checkBox3_CheckedChanged(object sender, EventArgs e)
        {
            bCookie = checkBox3.Checked;
        }
        bool bNoLimitedBC = false;
        private void checkBox4_CheckedChanged(object sender, EventArgs e)
        {
            bNoLimitedBC = checkBox4.Checked;
        }
        bool bGetCha = true;
        private void checkBox5_CheckedChanged(object sender, EventArgs e)
        {
            bGetCha = checkBox5.Checked;
        }

    }


    /// <summary>  
    /// 有关HTTP请求的辅助类  
    /// </summary>  
    public class HttpWebResponseUtility
    {
        /// <summary>  
        /// 创建GET方式的HTTP请求  
        /// </summary>  
        /// <param name="url">请求的URL</param>  
        /// <param name="timeout">请求的超时时间</param>  
        /// <param name="userAgent">请求的客户端浏览器信息，可以为空</param>  
        /// <param name="cookies">随同HTTP请求发送的Cookie信息，如果不需要身份验证可以为空</param>  
        /// <returns></returns>  
        public static HttpWebResponse CreateGetHttpResponse(string url, int? timeout, string userAgent, CookieCollection cookies)
        {
            if (string.IsNullOrEmpty(url))
            {
                throw new ArgumentNullException("url");
            }
            HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
            request.Method = "GET";
            request.UserAgent = "";
            if (!string.IsNullOrEmpty(userAgent))
            {
                request.UserAgent = userAgent;
            }
            if (timeout.HasValue)
            {
                request.Timeout = timeout.Value;
            }
            if (cookies != null)
            {
                request.CookieContainer = new CookieContainer();
                request.CookieContainer.Add(cookies);
            }
            return request.GetResponse() as HttpWebResponse;
        }
        
}
       
    }  